private Map<String, Map<String, Object>> toPropertiesByActions(Request request) { Map<String, Map<String, Object>> properties = new HashMap<>(); request.getParam(PARAM_ASSIGN, value -> properties.put(AssignAction.ASSIGN_KEY, new HashMap<>(of(ASSIGNEE_PARAMETER, value)))); request.getParam(PARAM_SET_SEVERITY, value -> properties.put(SET_SEVERITY_KEY, new HashMap<>(of(SEVERITY_PARAMETER, value)))); request.getParam(PARAM_SET_TYPE, value -> properties.put(SET_TYPE_KEY, new HashMap<>(of(TYPE_PARAMETER, value)))); request.getParam(PARAM_DO_TRANSITION, value -> properties.put(DO_TRANSITION_KEY, new HashMap<>(of(TRANSITION_PARAMETER, value)))); request.getParam(PARAM_ADD_TAGS, value -> properties.put(AddTagsAction.KEY, new HashMap<>(of(TAGS_PARAMETER, value)))); request.getParam(PARAM_REMOVE_TAGS, value -> properties.put(RemoveTagsAction.KEY, new HashMap<>(of(TAGS_PARAMETER, value)))); request.getParam(PARAM_COMMENT, value -> properties.put(COMMENT_KEY, new HashMap<>(of(COMMENT_PROPERTY, value)))); checkAtLeastOneActionIsDefined(properties.keySet()); return properties; }
private OrganizationDto getOrganization(DbSession dbSession, Request request) { String organizationKey = request.getParam(PARAM_ORGANIZATION) .or(defaultOrganizationProvider.get()::getKey); return checkFoundWithOptional( dbClient.organizationDao().selectByKey(dbSession, organizationKey), "No organization for key '%s'", organizationKey); }
@Override public void handle(Request request, Response response) throws Exception { userSession.checkLoggedIn(); try (DbSession dbSession = dbClient.openSession(false)) { organizationFlags.checkEnabled(dbSession); String key = request.mandatoryParam(PARAM_KEY); UpdateOrganizationRequest updateRequest = new UpdateOrganizationRequest( request.getParam(PARAM_NAME, (rqt, paramKey) -> wsSupport.getAndCheckName(rqt)), request.getParam(PARAM_DESCRIPTION, (rqt, paramKey) -> emptyAsNull(wsSupport.getAndCheckDescription(rqt))), request.getParam(PARAM_URL, (rqt, paramKey) -> emptyAsNull(wsSupport.getAndCheckUrl(rqt))), request.getParam(PARAM_AVATAR_URL, (rqt, paramKey) -> emptyAsNull(wsSupport.getAndCheckAvatar(rqt)))); OrganizationDto dto = getDto(dbSession, key); userSession.checkPermission(ADMINISTER, dto); dto.setName(updateRequest.getName().or(dto::getName)) .setDescription(updateRequest.getDescription().or(dto::getDescription)) .setUrl(updateRequest.getUrl().or(dto::getUrl)) .setAvatarUrl(updateRequest.getAvatar().or(dto::getAvatarUrl)); dbClient.organizationDao().update(dbSession, dto); dbSession.commit(); writeResponse(request, response, dto); } }
@Override public void handle(Request wsRequest, Response wsResponse) throws Exception { String organizationKey = wsRequest.getParam(PARAM_ORGANIZATION_KEY) .emptyAsNull() .or(defaultOrganizationProvider.get()::getKey); String projectKey = wsRequest.mandatoryParam(PARAM_PROJECT_KEY); String deprecatedBranch = wsRequest.param(PARAM_PROJECT_BRANCH); String projectName = abbreviate(defaultIfBlank(wsRequest.param(PARAM_PROJECT_NAME), projectKey), MAX_COMPONENT_NAME_LENGTH); Map<String, String> characteristics = parseTaskCharacteristics(wsRequest); try (InputStream report = new BufferedInputStream(wsRequest.mandatoryParamAsPart(PARAM_REPORT_DATA).getInputStream())) { CeTask task = reportSubmitter.submit(organizationKey, projectKey, deprecatedBranch, projectName, characteristics, report); Ce.SubmitResponse submitResponse = Ce.SubmitResponse.newBuilder() .setTaskId(task.getUuid()) .setProjectId(task.getComponent().get().getUuid()) .build(); WsUtils.writeProtobuf(submitResponse, wsRequest, wsResponse); } }
private Map<String, Map<String, Object>> toPropertiesByActions(Request request) { Map<String, Map<String, Object>> properties = new HashMap<>(); request.getParam(PARAM_ASSIGN, value -> properties.put(AssignAction.ASSIGN_KEY, new HashMap<>(of(ASSIGNEE_PARAMETER, value)))); request.getParam(PARAM_SET_SEVERITY, value -> properties.put(SET_SEVERITY_KEY, new HashMap<>(of(SEVERITY_PARAMETER, value)))); request.getParam(PARAM_SET_TYPE, value -> properties.put(SET_TYPE_KEY, new HashMap<>(of(TYPE_PARAMETER, value)))); request.getParam(PARAM_DO_TRANSITION, value -> properties.put(DO_TRANSITION_KEY, new HashMap<>(of(TRANSITION_PARAMETER, value)))); request.getParam(PARAM_ADD_TAGS, value -> properties.put(AddTagsAction.KEY, new HashMap<>(of(TAGS_PARAMETER, value)))); request.getParam(PARAM_REMOVE_TAGS, value -> properties.put(RemoveTagsAction.KEY, new HashMap<>(of(TAGS_PARAMETER, value)))); request.getParam(PARAM_COMMENT, value -> properties.put(COMMENT_KEY, new HashMap<>(of(COMMENT_PROPERTY, value)))); checkAtLeastOneActionIsDefined(properties.keySet()); return properties; }
private OrganizationDto getOrganization(DbSession dbSession, Request request) { String organizationKey = request.getParam(PARAM_ORGANIZATION) .or(defaultOrganizationProvider.get()::getKey); return checkFoundWithOptional( dbClient.organizationDao().selectByKey(dbSession, organizationKey), "No organization for key '%s'", organizationKey); }
@Override public void handle(Request request, Response response) throws Exception { userSession.checkLoggedIn(); try (DbSession dbSession = dbClient.openSession(false)) { organizationFlags.checkEnabled(dbSession); String key = request.mandatoryParam(PARAM_KEY); UpdateOrganizationRequest updateRequest = new UpdateOrganizationRequest( request.getParam(PARAM_NAME, (rqt, paramKey) -> wsSupport.getAndCheckName(rqt)), request.getParam(PARAM_DESCRIPTION, (rqt, paramKey) -> emptyAsNull(wsSupport.getAndCheckDescription(rqt))), request.getParam(PARAM_URL, (rqt, paramKey) -> emptyAsNull(wsSupport.getAndCheckUrl(rqt))), request.getParam(PARAM_AVATAR_URL, (rqt, paramKey) -> emptyAsNull(wsSupport.getAndCheckAvatar(rqt)))); OrganizationDto dto = getDto(dbSession, key); userSession.checkPermission(ADMINISTER, dto); dto.setName(updateRequest.getName().or(dto::getName)) .setDescription(updateRequest.getDescription().or(dto::getDescription)) .setUrl(updateRequest.getUrl().or(dto::getUrl)) .setAvatarUrl(updateRequest.getAvatar().or(dto::getAvatarUrl)); dbClient.organizationDao().update(dbSession, dto); dbSession.commit(); writeResponse(request, response, dto); } }
@Override public void handle(Request wsRequest, Response wsResponse) throws Exception { String organizationKey = wsRequest.getParam(PARAM_ORGANIZATION_KEY) .emptyAsNull() .or(defaultOrganizationProvider.get()::getKey); String projectKey = wsRequest.mandatoryParam(PARAM_PROJECT_KEY); String projectBranch = wsRequest.param(PARAM_PROJECT_BRANCH); String projectName = abbreviate(defaultIfBlank(wsRequest.param(PARAM_PROJECT_NAME), projectKey), MAX_COMPONENT_NAME_LENGTH); Map<String, String> characteristics = parseTaskCharacteristics(wsRequest); try (InputStream report = new BufferedInputStream(wsRequest.mandatoryParamAsPart(PARAM_REPORT_DATA).getInputStream())) { CeTask task = reportSubmitter.submit(organizationKey, projectKey, projectBranch, projectName, characteristics, report); Ce.SubmitResponse submitResponse = Ce.SubmitResponse.newBuilder() .setTaskId(task.getUuid()) .setProjectId(task.getComponentUuid()) .build(); WsUtils.writeProtobuf(submitResponse, wsRequest, wsResponse); } }