@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; } }
@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); }
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()); } }
protected void loadStack(StackImpl stack, Path imagePath) { setIconData(stack, imagePath); try { try { stackDao.update(stack); } catch (NotFoundException ignored) { stackDao.create(stack); } permissionsDao.store( new StackPermissionsImpl("*", stack.getId(), singletonList(StackDomain.SEARCH))); } catch (ServerException | ConflictException ex) { LOG.warn(format("Failed to load stack with id '%s' ", stack.getId()), ex.getMessage()); } } }
@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); } }
@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); } }
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); 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);
/** * 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); } } }
public StackImpl(StackImpl stack) { this( stack.getId(), stack.getName(), stack.getDescription(), stack.getScope(), stack.getCreator(), stack.getTags(), stack.getWorkspaceConfig(), stack.getComponents(), stack.getStackIcon()); }