public void removeImageAttachToRank(final Rank rank, final RankImage imageAttach) { LOG.info("removeImageAttachToRank(final Rank rank, final RankImage imageAttach)"); if (rank == null || imageAttach == null) { throw new IllegalArgumentException("Null Argument"); } if (!isRanksEnabled()) { LOG.warn("removeImageAttachToRank invoked, but ranks are disabled"); return; } HibernateCallback hcb = session -> { Rank returnedData = (Rank) session.get(RankImpl.class, rank.getId()); RankImage returnedAttach = (RankImage) session.get(RankImageImpl.class, Long.valueOf(imageAttach.getId())); if (returnedData != null) { returnedData.setRankImage(null); session.saveOrUpdate(returnedData); if (returnedAttach.getAttachmentId().toLowerCase().startsWith("/attachment")) try { contentHostingService.removeResource(returnedAttach.getAttachmentId()); session.delete(returnedAttach); } catch (PermissionException | IdUnusedException | TypeException | InUseException e) { e.printStackTrace(); } } return null; }; getHibernateTemplate().execute(hcb); }
public RankImage createRankImage() { RankImage image = new RankImageImpl(); image.setUuid(getNextUuid()); image.setCreated(new Date()); image.setCreatedBy(getCurrentUser()); image.setModified(new Date()); image.setModifiedBy(getCurrentUser()); LOG.info("createRankImage: Rank Image " + image.getUuid() + " created successfully"); return image; }
public RankImage createRankImageAttachmentObject(String attachId, String name) { if (!isRanksEnabled()) { LOG.warn("createRankImageAttachmentObject invoked, but ranks are disabled"); return null; } try { RankImage attach = new RankImageImpl(); attach.setCreated(new Date()); attach.setModified(new Date()); ContentResource cr = contentHostingService.getResource(attachId); User creator = userDirectoryService.getUser( cr.getProperties().getProperty(cr.getProperties().getNamePropCreator())); attach.setCreatedBy(creator.getDisplayName()); User modifier = userDirectoryService.getUser( cr.getProperties().getProperty(cr.getProperties().getNamePropModifiedBy())); attach.setModifiedBy(modifier.getDisplayName()); attach.setAttachmentSize((Long.valueOf(cr.getContentLength())).toString()); attach.setAttachmentId(attachId); attach.setAttachmentName(name); attach.setAttachmentType(cr.getContentType()); String tempString = cr.getUrl(); attach.setAttachmentUrl(resourceUrlEscaping(tempString)); getHibernateTemplate().saveOrUpdate(attach); return attach; } catch (Exception e) { e.printStackTrace(); return null; } }
public void addImageAttachToRank(final Rank rank, final RankImage imageAttach) { if (rank == null || imageAttach == null) { throw new IllegalArgumentException("Null Argument"); } if (!isRanksEnabled()) { LOG.warn("addImageAttachToRank invoked, but ranks are disabled"); return; } HibernateCallback hcb = session -> { Rank returnedData = (Rank) session.get(RankImpl.class, rank.getId()); if (returnedData != null) { imageAttach.setRank(rank); returnedData.setRankImage(imageAttach); session.save(returnedData); } return null; }; getHibernateTemplate().execute(hcb); }