Skip to content

Commit

Permalink
Merge branch 'master' into luceneRexexp
Browse files Browse the repository at this point in the history
  • Loading branch information
vparfonov committed Dec 20, 2017
2 parents a6bcb89 + 4025610 commit a8f6104
Show file tree
Hide file tree
Showing 89 changed files with 2,089 additions and 688 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
],
"source": {
"type": "image",
"origin": "eclipse/che-dev:che6"
"origin": "eclipse/che-dev:nightly"
},
"workspaceConfig": {
"environments": {
Expand Down Expand Up @@ -68,7 +68,7 @@
}
},
"recipe": {
"location": "eclipse/che-dev:che6",
"location": "eclipse/che-dev:nightly",
"type": "dockerimage"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public class DefaultHttpJsonRequest implements HttpJsonRequest {
private String method;
private Object body;
private List<Pair<String, ?>> queryParams;
private List<Pair<String, String>> headers;
private String authorizationHeaderValue;

protected DefaultHttpJsonRequest(String url, String method) {
Expand Down Expand Up @@ -118,6 +119,16 @@ public HttpJsonRequest addQueryParam(@NotNull String name, @NotNull Object value
return this;
}

public HttpJsonRequest addHeader(@NotNull String name, @NotNull String value) {
requireNonNull(name, "Required non-null header name");
requireNonNull(value, "Required non-null header value");
if (headers == null) {
headers = new ArrayList<>();
}
headers.add(Pair.of(name, value));
return this;
}

@Override
public HttpJsonRequest setAuthorizationHeader(@NotNull String value) {
requireNonNull(value, "Required non-null header value");
Expand Down Expand Up @@ -149,7 +160,7 @@ public HttpJsonResponse request()
if (method == null) {
throw new IllegalStateException("Could not perform request, request method wasn't set");
}
return doRequest(timeout, url, method, body, queryParams, authorizationHeaderValue);
return doRequest(timeout, url, method, body, queryParams, authorizationHeaderValue, headers);
}

/**
Expand Down Expand Up @@ -182,7 +193,8 @@ protected DefaultHttpJsonResponse doRequest(
String method,
Object body,
List<Pair<String, ?>> parameters,
String authorizationHeaderValue)
String authorizationHeaderValue,
List<Pair<String, String>> headers)
throws IOException, ServerException, ForbiddenException, NotFoundException,
UnauthorizedException, ConflictException, BadRequestException {
final String authToken = EnvironmentContext.getCurrent().getSubject().getToken();
Expand All @@ -202,6 +214,15 @@ protected DefaultHttpJsonResponse doRequest(
final HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
conn.setConnectTimeout(timeout > 0 ? timeout : 60000);
conn.setReadTimeout(timeout > 0 ? timeout : 60000);

final boolean hasHeaders = headers != null && !headers.isEmpty();

if (hasHeaders) {
for (Pair<String, String> header : headers) {
conn.setRequestProperty(header.first, header.second);
}
}

try {
conn.setRequestMethod(method);
// drop a hint for server side that we want to receive application/json
Expand All @@ -225,7 +246,6 @@ protected DefaultHttpJsonResponse doRequest(
output.write(DtoFactory.getInstance().toJson(body).getBytes());
}
}

final int responseCode = conn.getResponseCode();
if ((responseCode / 100) != 2) {
InputStream in = conn.getErrorStream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@ public interface HttpJsonRequest {
*/
HttpJsonRequest addQueryParam(@NotNull String name, @NotNull Object value);

/**
* Adds header to the request.
*
* @param name header name
* @param value header value
* @return this request instance
* @throws NullPointerException when either header name or value is null
*/
HttpJsonRequest addHeader(@NotNull String name, @NotNull String value);

/**
* Adds authorization header to the request.
*
Expand Down Expand Up @@ -206,4 +216,16 @@ default HttpJsonRequest addQueryParams(@NotNull Map<String, ?> params) {
params.forEach(this::addQueryParam);
return this;
}

/**
* Adds set of headers to this request.
*
* @param headers map with headers
* @return this request instance
*/
default HttpJsonRequest addHeaders(@NotNull Map<String, String> headers) {
Objects.requireNonNull(headers, "Required non-null headers");
headers.forEach(this::addHeader);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@ public void shouldUseUrlAndMethodFromTheLinks() throws Exception {
anyString(),
nullable(Object.class),
nullable(List.class),
nullable(String.class));
nullable(String.class),
nullable(List.class));
request.request();

verify(request).doRequest(0, DEFAULT_URL, "POST", null, null, null);
verify(request).doRequest(0, DEFAULT_URL, "POST", null, null, null, null);
}

@Test
Expand All @@ -119,6 +120,7 @@ public void shouldBeAbleToMakeRequest() throws Exception {
.setTimeout(10_000_000)
.addQueryParam("name", "value")
.addQueryParam("name2", "value2")
.addHeader("Connection", "close")
.request();

verify(request)
Expand All @@ -128,7 +130,8 @@ public void shouldBeAbleToMakeRequest() throws Exception {
"PUT",
body,
asList(Pair.of("name", "value"), Pair.of("name2", "value2")),
null);
null,
asList(Pair.of("Connection", "close")));
}

@Test
Expand All @@ -146,6 +149,7 @@ public void shouldBeAbleToUseStringMapAsRequestBody() throws Exception {
eq("POST"),
mapCaptor.capture(),
eq(null),
eq(null),
eq(null));
assertTrue(mapCaptor.getValue() instanceof JsonStringMap);
assertEquals(mapCaptor.getValue(), body);
Expand All @@ -164,6 +168,7 @@ public void shouldBeAbleToUseListOfJsonSerializableElementsAsRequestBody() throw
eq("POST"),
listCaptor.capture(),
eq(null),
eq(null),
eq(null));
assertTrue(listCaptor.getValue() instanceof JsonArray);
assertEquals(listCaptor.getValue(), body);
Expand All @@ -172,7 +177,7 @@ public void shouldBeAbleToUseListOfJsonSerializableElementsAsRequestBody() throw
@Test
public void defaultMethodIsGet() throws Exception {
request.request();
verify(request).doRequest(0, DEFAULT_URL, HttpMethod.GET, null, null, null);
verify(request).doRequest(0, DEFAULT_URL, HttpMethod.GET, null, null, null, null);
}

@Test(expectedExceptions = NullPointerException.class)
Expand Down Expand Up @@ -216,6 +221,21 @@ public void shouldThrowNullPointerExceptionWhenQueryParamsAreNull() throws Excep
new DefaultHttpJsonRequest("http://localhost:8080").addQueryParams(null);
}

@Test(expectedExceptions = NullPointerException.class)
public void shouldThrowNullPointerExceptionWhenHeaderNameIsNull() throws Exception {
new DefaultHttpJsonRequest("http://localhost:8080").addHeader(null, "close");
}

@Test(expectedExceptions = NullPointerException.class)
public void shouldThrowNullPointerExceptionWhenHeaderValueIsNull() throws Exception {
new DefaultHttpJsonRequest("http://localhost:8080").addHeader("Connection", null);
}

@Test(expectedExceptions = NullPointerException.class)
public void shouldThrowNullPointerExceptionWhenHeadersAreNull() throws Exception {
new DefaultHttpJsonRequest("http://localhost:8080").addHeaders(null);
}

@Test(expectedExceptions = NullPointerException.class)
public void shouldThrowNullPointerExceptionWhenLinkHrefIsNull() throws Exception {
new DefaultHttpJsonRequest(createLink("GET", null, null));
Expand Down Expand Up @@ -375,6 +395,7 @@ private void prepareResponse(String response) throws Exception {
anyString(),
nullable(Object.class),
nullable(List.class),
nullable(String.class));
nullable(String.class),
nullable(List.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ public interface Machine {
* </pre>
*/
Map<String, ? extends Server> getServers();

MachineStatus getStatus();
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ public enum MachineStatus {
STOPPED,

/** Machine failed */
FAILED;
FAILED
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<che-toolbar che-title="Workspaces" border-none></che-toolbar>
<che-description che-link-title="Learn more." che-link="{{branding.docs.workspace}}">A workspace is where your projects live and run. Create workspaces from stacks that define projects, runtimes, and commands.</che-description>
<md-content md-scroll-y flex layout="column" md-theme="maincontent-theme">
<md-progress-linear md-mode="indeterminate" class="workspaces-list-progress"
ng-show="listWorkspacesCtrl.isInfoLoading"></md-progress-linear>
<md-progress-linear md-mode="indeterminate" class="progress-line"
ng-show="listWorkspacesCtrl.isInfoLoading || listWorkspacesCtrl.isRequestPending"></md-progress-linear>
<md-content flex class="workspace-list-content" ng-hide="listWorkspacesCtrl.isInfoLoading">
<che-list-header che-input-placeholder="Search"
che-search-model="listWorkspacesCtrl.workspaceFilter.config.name"
Expand Down Expand Up @@ -70,6 +70,7 @@
<che-workspace-item
ng-repeat="workspace in listWorkspacesCtrl.cheListHelper.getVisibleItems() | orderBy:[listWorkspacesCtrl.workspaceOrderBy, 'config.name']"
ng-model="listWorkspacesCtrl.cheListHelper.itemsSelectionStatus[workspace.id]"
is-request-pending="listWorkspacesCtrl.isRequestPending"
che-selectable="true"
che-display-labels="false"
che-on-checkbox-click="listWorkspacesCtrl.cheListHelper.updateBulkSelectionStatus()"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
flex-wrap wrap

.workspace-list-content
margin 0

md-progress-linear.workspaces-list-progress
height 10px
margin: 5px 0 0 0

.workspace-resources-locked
background-color red
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,24 @@
* Expects in parent scope:
* @param{object} workspace
*/
export class CheWorkspaceItem {
restrict: string;
require: string[];
templateUrl: string;
controller: string;
controllerAs: string;
bindToController: boolean;
scope: {
[propName: string]: string;
export class CheWorkspaceItem implements ng.IDirective {
restrict = 'E';
// we require ngModel as we want to use it inside our directive
require = ['ngModel'];

templateUrl = 'app/workspaces/list-workspaces/workspace-item/workspace-item.html';

controller = 'WorkspaceItemCtrl';
controllerAs = 'workspaceItemCtrl';
bindToController = true;
// scope values
scope = {
workspace: '=cheWorkspaceItem',
isSelectable: '=cheSelectable',
isSelect: '=?ngModel',
onCheckboxClick: '&?cheOnCheckboxClick',
displayLabels: '=cheDisplayLabels',
isRequestPending: '=?'
};

/**
* Default constructor.
*/
constructor() {
this.restrict = 'E';

// we require ngModel as we want to use it inside our directive
this.require = ['ngModel'];

// scope values
this.scope = {
workspace: '=cheWorkspaceItem',
isSelectable: '=cheSelectable',
isSelect: '=?ngModel',
onCheckboxClick: '&?cheOnCheckboxClick',
displayLabels : '=cheDisplayLabels'
};

this.templateUrl = 'app/workspaces/list-workspaces/workspace-item/workspace-item.html';


this.controller = 'WorkspaceItemCtrl';
this.controllerAs = 'workspaceItemCtrl';
this.bindToController = true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@
class="workspace-item-actions">
<span class="che-xs-header noselect" hide-gt-xs>Actions</span>
<span class="che-list-actions">
<che-workspace-status che-workspace-item="workspaceItemCtrl.workspace"></che-workspace-status>
<a ng-href="#/workspace/{{workspaceItemCtrl.workspace.namespace}}/{{workspaceItemCtrl.workspace.config.name}}?tab=Config"
<che-workspace-status workspace-id="workspaceItemCtrl.workspace.id"
is-request-pending="workspaceItemCtrl.isRequestPending"></che-workspace-status>
<a href="#/workspace/{{workspaceItemCtrl.workspace.namespace}}/{{workspaceItemCtrl.workspace.config.name}}?tab=Config"
uib-tooltip="Configure workspace">
<span class="fa fa-cog"></span>
</a>
Expand Down
Loading

0 comments on commit a8f6104

Please sign in to comment.