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()); }
public static StackBuilder builder() { return new StackBuilder(); }
@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; } }
@Override public void onCascadeEvent(BeforeStackRemovedEvent event) throws Exception { removeStackPermissions(event.getStack().getId(), PAGE_SIZE); }
@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; }
@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 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); } }
@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(); } }
@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()); } }
@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, 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(); }
@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(); } }
@Override @Transactional public StackImpl getById(String id) throws NotFoundException, ServerException { requireNonNull(id, "Required non-null id"); try { final StackImpl stack = managerProvider.get().find(StackImpl.class, id); if (stack == null) { throw new NotFoundException(format("Stack with id '%s' doesn't exist", id)); } return new StackImpl(stack); } catch (RuntimeException x) { throw new ServerException(x.getLocalizedMessage(), x); } }
@Override @Transactional public StackImpl getById(String id) throws NotFoundException, ServerException { requireNonNull(id, "Required non-null id"); try { final StackImpl stack = managerProvider.get().find(StackImpl.class, id); if (stack == null) { throw new NotFoundException(format("Stack with id '%s' doesn't exist", id)); } return new StackImpl(stack); } catch (RuntimeException x) { throw new ServerException(x.getLocalizedMessage(), x); } }