Search in sources :

Example 1 with TriState

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;
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) User(com.thoughtworks.go.domain.User) Collection(java.util.Collection) TriState(com.thoughtworks.go.util.TriState) Map(java.util.Map)

Example 2 with TriState

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);
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) NullAgentInstance(com.thoughtworks.go.domain.NullAgentInstance) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) HttpException(com.thoughtworks.go.config.exceptions.HttpException) AgentUpdateRequest(com.thoughtworks.go.apiv7.agents.model.AgentUpdateRequest) TriState(com.thoughtworks.go.util.TriState) HttpException(com.thoughtworks.go.config.exceptions.HttpException) InvalidAgentInstructionException(com.thoughtworks.go.domain.exception.InvalidAgentInstructionException) IOException(java.io.IOException)

Example 3 with TriState

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;
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) User(com.thoughtworks.go.domain.User) Collection(java.util.Collection) TriState(com.thoughtworks.go.util.TriState) Map(java.util.Map)

Aggregations

TriState (com.thoughtworks.go.util.TriState)3 User (com.thoughtworks.go.domain.User)2 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)2 Collection (java.util.Collection)2 Map (java.util.Map)2 AgentUpdateRequest (com.thoughtworks.go.apiv7.agents.model.AgentUpdateRequest)1 HttpException (com.thoughtworks.go.config.exceptions.HttpException)1 AgentInstance (com.thoughtworks.go.domain.AgentInstance)1 NullAgentInstance (com.thoughtworks.go.domain.NullAgentInstance)1 InvalidAgentInstructionException (com.thoughtworks.go.domain.exception.InvalidAgentInstructionException)1 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)1 IOException (java.io.IOException)1