private void haltIfEntityWithSameIdExists(ConfigRepoConfig repo) { String id = repo.getId(); if (doFetchEntityFromConfig(id) == null) { return; } repo.addError("id", "ConfigRepo ids should be unique. A ConfigRepo with the same id already exists."); throw haltBecauseEntityAlreadyExists(jsonWriter(repo), "config-repo", id); } }
private void haltIfEntityWithSameIdExists(ElasticProfile elasticProfile) { if (elasticProfileService.findProfile(elasticProfile.getId()) == null) { return; } elasticProfile.addError("id", format("Elastic profile ids should be unique. Elastic profile with id '%s' already exists.", elasticProfile.getId())); throw haltBecauseEntityAlreadyExists(jsonWriter(elasticProfile), "elasticProfile", elasticProfile.getId()); } }
private void haltIfEntityWithSameIdExists(ArtifactStore artifactStore) { if (artifactStoreService.findArtifactStore(artifactStore.getId()) == null) { return; } artifactStore.addError("id", "Artifact store ids should be unique. Artifact store with the same id exists."); throw haltBecauseEntityAlreadyExists(jsonWriter(artifactStore), "artifactStore", artifactStore.getId()); } }
private void haltIfEntityBySameNameInRequestExists(Request req, Role role) { if (roleConfigService.findRole(role.getName().toString()) == null) { return; } role.addError("name", "Role names should be unique. Role with the same name exists."); throw haltBecauseEntityAlreadyExists(jsonWriter(role), "role", role.getName()); } }
private void haltIfEntityBySameNameInRequestExists(Request req, Role role) { if (roleConfigService.findRole(role.getName().toString()) == null) { return; } role.addError("name", "Role names should be unique. Role with the same name exists."); throw haltBecauseEntityAlreadyExists(jsonWriter(role), "role", role.getName()); } }
public String create(Request req, Response res) throws Exception { HttpLocalizedOperationResult result = new HttpLocalizedOperationResult(); User user = buildUserEntityFromRequestBody(req, false); if (!userService.findUserByName(user.getName()).equals(new NullUser())) { throw haltBecauseEntityAlreadyExists(jsonWriter(user, new HashMap<>()), "User", user.getName()); } return saveUserAndRenderResult(req, res, result, user, user, user.getName()); }
public String create(Request req, Response res) { PipelineConfigs pipelineConfigsFromReq = buildEntityFromRequestBody(req); String groupName = pipelineConfigsFromReq.getGroup(); Optional<PipelineConfigs> pipelineConfigsFromServer = findPipelineGroup(groupName); if (pipelineConfigsFromServer.isPresent()) { pipelineConfigsFromReq.addError("name", LocalizedMessage.resourceAlreadyExists("pipeline group", groupName)); throw haltBecauseEntityAlreadyExists(jsonWriter(pipelineConfigsFromReq), "pipeline group", groupName); } HttpLocalizedOperationResult result = new HttpLocalizedOperationResult(); pipelineConfigsService.createGroup(SessionUtils.currentUsername(), pipelineConfigsFromReq, result); return handleCreateOrUpdateResponse(req, res, pipelineConfigsFromReq, result); }
private void haltIfEntityWithSameNameExists(EnvironmentConfig environmentConfig) { HttpLocalizedOperationResult result = new HttpLocalizedOperationResult(); ConfigElementForEdit<EnvironmentConfig> existingEnvironmentConfig = environmentConfigService.getMergedEnvironmentforDisplay(environmentConfig.name().toString(), result); if (existingEnvironmentConfig == null) { return; } environmentConfig.addError("name", format("Environment name should be unique. Environment with name '%s' already exists.", environmentConfig.name().toString())); throw haltBecauseEntityAlreadyExists(jsonWriter(environmentConfig), "environment", environmentConfig.name().toString()); }
private void haltIfEntityBySameNameInRequestExists(PipelineConfig pipelineConfig) { if (pipelineConfigService.getPipelineConfig(pipelineConfig.name().toString()) == null) { return; } pipelineConfig.addError("name", LocalizedMessage.resourceAlreadyExists("pipeline", pipelineConfig.name().toString())); throw haltBecauseEntityAlreadyExists(jsonWriter(pipelineConfig), "pipeline", pipelineConfig.getName()); } }
private void haltIfEntityBySameNameInRequestExists(PipelineTemplateConfig templateConfig, HttpLocalizedOperationResult result) { if (templateConfigService.loadForView(templateConfig.name().toString(), result) == null) { return; } templateConfig.addError("name", LocalizedMessage.resourceAlreadyExists("template", templateConfig.name().toString())); throw haltBecauseEntityAlreadyExists(jsonWriter(templateConfig), "template", templateConfig.name()); } }