use of com.thoughtworks.go.util.TriState in project gocd by gocd.
the class CurrentUserControllerDelegate method update.
public String update(Request req, Response res) throws IOException {
User user = userService.findUserByName(currentUserLoginName().toString());
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
Map map = readRequestBodyAsJSON(req);
String checkinAliases = null;
if (map.containsKey("checkin_aliases")) {
Object newAliases = map.get("checkin_aliases");
if (newAliases instanceof Collection) {
checkinAliases = StringUtils.join((Collection) newAliases, ", ");
} else if (newAliases instanceof String) {
checkinAliases = (String) newAliases;
}
}
TriState emailMe = TriState.from(String.valueOf(map.get("email_me")));
String email = (String) map.get("email");
User serializedUser = userService.save(user, TriState.from(null), emailMe, email, checkinAliases, result);
String json = jsonizeAsTopLevelObject(req, writer -> UserRepresenter.toJSON(writer, serializedUser));
String etag = etagFor(json);
setEtagHeader(res, etag);
return json;
}
use of com.thoughtworks.go.util.TriState in project gocd by gocd.
the class AgentsControllerV7 method update.
public String update(Request request, Response response) {
String uuid = request.params("uuid");
AgentUpdateRequest req = fromJSON(request.body());
String hostname = req.getHostname();
String resources = req.getResources();
String environments = filterOutEnvsWhichAreAssociatedViaConfigRepo(uuid, req.getEnvironments());
TriState configState = req.getAgentConfigState();
HttpOperationResult result = new HttpOperationResult();
AgentInstance updatedAgentInstance = null;
try {
updatedAgentInstance = agentService.updateAgentAttributes(uuid, hostname, resources, environments, configState);
handleUpdateAgentResponse(updatedAgentInstance, result);
} catch (HttpException e) {
throw e;
} catch (Exception e) {
throw halt(HttpStatus.SC_INTERNAL_SERVER_ERROR, MessageJson.create(e.getMessage()));
}
return handleCreateOrUpdateResponse(request, response, updatedAgentInstance, result);
}
use of com.thoughtworks.go.util.TriState in project gocd by gocd.
the class CurrentUserController method update.
public String update(Request req, Response res) {
User user = userService.findUserByName(currentUserLoginName().toString());
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
Map map = readRequestBodyAsJSON(req);
String checkinAliases = null;
if (map.containsKey("checkin_aliases")) {
Object newAliases = map.get("checkin_aliases");
if (newAliases instanceof Collection) {
checkinAliases = StringUtils.join((Collection) newAliases, ", ");
} else if (newAliases instanceof String) {
checkinAliases = (String) newAliases;
}
}
TriState emailMe = TriState.from(String.valueOf(map.get("email_me")));
String email = (String) map.get("email");
User serializedUser = userService.save(user, TriState.from(null), emailMe, email, checkinAliases, result);
res.status(result.httpCode());
String json = jsonizeAsTopLevelObject(req, writer -> UserRepresenter.toJSON(writer, serializedUser, result));
String etag = etagFor(json);
setEtagHeader(res, etag);
return json;
}
Aggregations