public StackImpl build() { return new StackImpl( id, name, description, scope, creator, tags, workspaceConfig, components, stackIcon); } }
public StackImpl(StackImpl stack) { this( stack.getId(), stack.getName(), stack.getDescription(), stack.getScope(), stack.getCreator(), stack.getTags(), stack.getWorkspaceConfig(), stack.getComponents(), stack.getStackIcon()); }
@Override public int hashCode() { int hash = 7; hash = 31 * hash + Objects.hashCode(id); hash = 31 * hash + Objects.hashCode(name); hash = 31 * hash + Objects.hashCode(description); hash = 31 * hash + Objects.hashCode(scope); hash = 31 * hash + Objects.hashCode(creator); hash = 31 * hash + getTags().hashCode(); hash = 31 * hash + Objects.hashCode(workspaceConfig); hash = 31 * hash + getComponents().hashCode(); hash = 31 * hash + Objects.hashCode(stackIcon); return hash; }
@Override public StackImpl update(StackImpl update) throws NotFoundException, ServerException, ConflictException { requireNonNull(update, "Required non-null update"); try { return new StackImpl(doUpdate(update)); } catch (DuplicateKeyException x) { throw new ConflictException(format("Stack with name '%s' already exists", update.getName())); } catch (RuntimeException x) { throw new ServerException(x.getLocalizedMessage(), x); } }
@Override public void create(StackImpl stack) throws ConflictException, ServerException { requireNonNull(stack, "Required non-null stack"); try { doCreate(stack); } catch (DuplicateKeyException x) { throw new ConflictException( format("Stack with id '%s' or name '%s' already exists", stack.getId(), stack.getName())); } catch (RuntimeException x) { throw new ServerException(x.getLocalizedMessage(), x); } }
@Transactional protected StackImpl doUpdate(StackImpl update) throws NotFoundException { final EntityManager manager = managerProvider.get(); if (manager.find(StackImpl.class, update.getId()) == null) { throw new NotFoundException(format("Workspace with id '%s' doesn't exist", update.getId())); } if (update.getWorkspaceConfig() != null) { update.getWorkspaceConfig().getProjects().forEach(ProjectConfigImpl::prePersistAttributes); } StackImpl merged = manager.merge(update); manager.flush(); return merged; } }
/** * Searches for stack icon and set image data into given stack. * * @param stack stack for icon setup * @param stackIconFolderPath path to icon folder */ protected void setIconData(StackImpl stack, Path stackIconFolderPath) { StackIcon stackIcon = stack.getStackIcon(); if (stackIcon == null) { return; } if (stackIconFolderPath == null) { stack.setStackIcon(null); LOG.warn("No configured image found for stack {}", stack.getId()); return; } try { final Path stackIconPath = stackIconFolderPath.resolve(stackIcon.getName()); final byte[] imageData = IOUtils.toByteArray(IoUtil.getResource(stackIconPath.toString())); stackIcon = new StackIcon(stackIcon.getName(), stackIcon.getMediaType(), imageData); stack.setStackIcon(stackIcon); } catch (IOException ex) { stack.setStackIcon(null); LOG.error( format("Failed to load stack icon data for the stack with id '%s'", stack.getId()), ex); } } }
@Override public void onCascadeEvent(BeforeStackRemovedEvent event) throws Exception { removeStackPermissions(event.getStack().getId(), PAGE_SIZE); }
LinksHelper.createLink( "DELETE", builder.clone().path(getClass(), "removeStack").build(stack.getId()).toString(), LINK_REL_REMOVE_STACK); final Link getLink = LinksHelper.createLink( "GET", builder.clone().path(getClass(), "getStack").build(stack.getId()).toString(), APPLICATION_JSON, LINK_REL_GET_STACK_BY_ID); links.add(getLink); StackIcon stackIcon = stack.getStackIcon(); if (stackIcon != null) { Link deleteIcon = LinksHelper.createLink( "DELETE", builder.clone().path(getClass(), "removeIcon").build(stack.getId()).toString(), stackIcon.getMediaType(), LINK_REL_DELETE_ICON); LinksHelper.createLink( "GET", builder.clone().path(getClass(), "getIcon").build(stack.getId()).toString(), stackIcon.getMediaType(), LINK_REL_GET_ICON);
@Transactional(rollbackOn = {RuntimeException.class, ApiException.class}) protected void doCreate(StackImpl stack) throws ConflictException, ServerException { if (stack.getWorkspaceConfig() != null) { stack.getWorkspaceConfig().getProjects().forEach(ProjectConfigImpl::prePersistAttributes); } EntityManager manager = managerProvider.get(); manager.persist(stack); manager.flush(); eventService.publish(new StackPersistedEvent(stack)).propagateException(); }
StackImpl.builder() .setId(id) .setName(updateDto.getName()) .setScope(updateDto.getScope()) .setCreator(stack.getCreator()) .setTags(updateDto.getTags()) .setWorkspaceConfig(updateDto.getWorkspaceConfig())
final String userId = EnvironmentContext.getCurrent().getSubject().getUserId(); final StackImpl newStack = StackImpl.builder() .generateId() .setName(stackDto.getName())
@Override public StackImpl update(StackImpl update) throws NotFoundException, ServerException, ConflictException { requireNonNull(update, "Required non-null update"); try { return new StackImpl(doUpdate(update)); } catch (DuplicateKeyException x) { throw new ConflictException(format("Stack with name '%s' already exists", update.getName())); } catch (RuntimeException x) { throw new ServerException(x.getLocalizedMessage(), x); } }
@Override public void create(StackImpl stack) throws ConflictException, ServerException { requireNonNull(stack, "Required non-null stack"); try { doCreate(stack); } catch (DuplicateKeyException x) { throw new ConflictException( format("Stack with id '%s' or name '%s' already exists", stack.getId(), stack.getName())); } catch (RuntimeException x) { throw new ServerException(x.getLocalizedMessage(), x); } }
@Transactional protected StackImpl doUpdate(StackImpl update) throws NotFoundException { final EntityManager manager = managerProvider.get(); if (manager.find(StackImpl.class, update.getId()) == null) { throw new NotFoundException(format("Workspace with id '%s' doesn't exist", update.getId())); } if (update.getWorkspaceConfig() != null) { update.getWorkspaceConfig().getProjects().forEach(ProjectConfigImpl::prePersistAttributes); } StackImpl merged = manager.merge(update); manager.flush(); return merged; } }
protected void loadStack(StackImpl stack, Path imagePath) { setIconData(stack, imagePath); try { try { stackDao.update(stack); } catch (NotFoundException ex) { stackDao.create(stack); } } catch (ServerException | ConflictException ex) { LOG.warn(format("Failed to load stack with id '%s' ", stack.getId()), ex.getMessage()); } }
@Transactional(rollbackOn = {RuntimeException.class, ApiException.class}) protected void doCreate(StackImpl stack) throws ConflictException, ServerException { if (stack.getWorkspaceConfig() != null) { stack.getWorkspaceConfig().getProjects().forEach(ProjectConfigImpl::prePersistAttributes); } EntityManager manager = managerProvider.get(); manager.persist(stack); manager.flush(); eventService.publish(new StackPersistedEvent(stack)).propagateException(); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof StackImpl)) { return false; } final StackImpl that = (StackImpl) obj; return Objects.equals(id, that.id) && Objects.equals(name, that.name) && Objects.equals(description, that.description) && Objects.equals(scope, that.scope) && Objects.equals(creator, that.creator) && getTags().equals(that.getTags()) && Objects.equals(workspaceConfig, that.workspaceConfig) && getComponents().equals(that.getComponents()) && Objects.equals(stackIcon, that.stackIcon); }
@Transactional(rollbackOn = {RuntimeException.class, ServerException.class}) protected void doRemove(String id) throws ServerException { final EntityManager manager = managerProvider.get(); final StackImpl stack = manager.find(StackImpl.class, id); if (stack != null) { eventService.publish(new BeforeStackRemovedEvent(new StackImpl(stack))).propagateException(); manager.remove(stack); manager.flush(); } }