@Override public int hashCode() { int hash = 7; hash = 31 * hash + Objects.hashCode(id); hash = 31 * hash + Objects.hashCode(path); hash = 31 * hash + Objects.hashCode(name); hash = 31 * hash + Objects.hashCode(type); hash = 31 * hash + Objects.hashCode(description); hash = 31 * hash + Objects.hashCode(source); hash = 31 * hash + getMixins().hashCode(); hash = 31 * hash + getAttributes().hashCode(); return hash; }
final List<ProjectConfigImpl> projects = workspace.getConfig().getProjects(); final String normalizedPath = path.startsWith("/") ? path : '/' + path; if (!projects.removeIf(project -> project.getPath().equals(normalizedPath))) { throw new NotFoundException( format("Workspace '%s' doesn't contain project with path '%s'", id, normalizedPath)); projects.add(new ProjectConfigImpl(update)); return asDtoWithLinksAndToken(doUpdate(id, workspace));
/** * Synchronizes instance attributes with db attributes, should be called by internal components in * needed places, this can't be done neither by {@link PrePersist} nor by {@link PreUpdate} as * when the entity is merged the transient attribute won't be passed to event handlers. */ public void prePersistAttributes() { if (dbAttributes == null) { dbAttributes = new HashMap<>(); } final Map<String, Attribute> dbAttrsCopy = new HashMap<>(dbAttributes); dbAttributes.clear(); for (Map.Entry<String, List<String>> entry : getAttributes().entrySet()) { Attribute attribute = dbAttrsCopy.get(entry.getKey()); if (attribute == null) { attribute = new Attribute(entry.getKey(), entry.getValue()); } else if (!Objects.equals(attribute.values, entry.getValue())) { attribute.values = entry.getValue(); } dbAttributes.put(entry.getKey(), attribute); } }
@DELETE @Path("/{id}/project/{path:.*}") @ApiOperation( value = "Remove the project from the workspace", notes = "This operation can be performed only by the workspace owner") @ApiResponses({ @ApiResponse(code = 204, message = "The project successfully removed"), @ApiResponse(code = 403, message = "The user does not have access remove the project"), @ApiResponse(code = 404, message = "The workspace not found"), @ApiResponse(code = 500, message = "Internal server error occurred") }) public void deleteProject( @ApiParam("The workspace id") @PathParam("id") String id, @ApiParam("The name of the project to remove") @PathParam("path") String path) throws ServerException, BadRequestException, NotFoundException, ConflictException, ForbiddenException { final WorkspaceImpl workspace = workspaceManager.getWorkspace(id); final String normalizedPath = path.startsWith("/") ? path : '/' + path; if (workspace .getConfig() .getProjects() .removeIf(project -> project.getPath().equals(normalizedPath))) { doUpdate(id, workspace); } }
@POST @Path("/{id}/project") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation( value = "Adds a new project to the workspace", notes = "This operation can be performed only by the workspace owner") @ApiResponses({ @ApiResponse(code = 200, message = "The project successfully added to the workspace"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse(code = 403, message = "The user does not have access to add the project"), @ApiResponse(code = 404, message = "The workspace not found"), @ApiResponse(code = 409, message = "Any conflict error occurs"), @ApiResponse(code = 500, message = "Internal server error occurred") }) public WorkspaceDto addProject( @ApiParam("The workspace id") @PathParam("id") String id, @ApiParam(value = "The new project", required = true) ProjectConfigDto newProject) throws ServerException, BadRequestException, NotFoundException, ConflictException, ForbiddenException { requiredNotNull(newProject, "New project config"); final WorkspaceImpl workspace = workspaceManager.getWorkspace(id); workspace.getConfig().getProjects().add(new ProjectConfigImpl(newProject)); return asDtoWithLinksAndToken(doUpdate(id, workspace)); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof ProjectConfigImpl)) { return false; } final ProjectConfigImpl that = (ProjectConfigImpl) obj; return Objects.equals(id, that.id) && Objects.equals(path, that.path) && Objects.equals(name, that.name) && Objects.equals(type, that.type) && Objects.equals(description, that.description) && Objects.equals(source, that.source) && getMixins().equals(that.getMixins()) && getAttributes().equals(that.getAttributes()); }