public void update(String userId, Entry entry) { if (entry == null) { return; } authorization.expectWrite(userId, entry); boolean scheduleRebuild = sequenceDAO.hasSequence(entry.getId()); entry.setModificationTime(Calendar.getInstance().getTime()); if (entry.getVisibility() == null) entry.setVisibility(Visibility.OK.getValue()); entry = dao.update(entry); // check pi email String piEmail = entry.getPrincipalInvestigatorEmail(); if (StringUtils.isNotEmpty(piEmail)) { Account pi = DAOFactory.getAccountDAO().getByEmail(piEmail); if (pi != null) { // add write permission for the PI (method also checks to see if permission already exists) AccessPermission accessPermission = new AccessPermission(); accessPermission.setArticle(AccessPermission.Article.ACCOUNT); accessPermission.setArticleId(pi.getId()); accessPermission.setType(AccessPermission.Type.WRITE_ENTRY); accessPermission.setTypeId(entry.getId()); permissionsController.addPermission(userId, accessPermission); } } if (scheduleRebuild) { ApplicationController.scheduleBlastIndexRebuildTask(true); } }
public long updatePart(String userId, long partId, PartData part) { Entry existing = dao.get(partId); authorization.expectWrite(userId, existing); Entry entry = InfoToModelFactory.updateEntryField(part, existing); entry.getLinkedEntries().clear(); if (part.getLinkedParts() != null && part.getLinkedParts().size() > 0) { for (PartData data : part.getLinkedParts()) { Entry linked = dao.getByPartNumber(data.getPartId()); // check permissions on link if (!authorization.canRead(userId, linked)) { continue; } if (!canLink(entry, linked)) continue; entry.getLinkedEntries().add(linked); } } entry.setModificationTime(Calendar.getInstance().getTime()); if (entry.getVisibility() == Visibility.DRAFT.getValue()) { List<EntryField> invalidFields = EntryUtil.validates(part); if (invalidFields.isEmpty()) entry.setVisibility(Visibility.OK.getValue()); } entry = dao.update(entry); // check pi email String piEmail = entry.getPrincipalInvestigatorEmail(); if (StringUtils.isNotEmpty(piEmail)) { Account pi = DAOFactory.getAccountDAO().getByEmail(piEmail); if (pi != null) { // add write permission for the PI (method also checks to see if permission already exists) AccessPermission accessPermission = new AccessPermission(); accessPermission.setArticle(AccessPermission.Article.ACCOUNT); accessPermission.setArticleId(pi.getId()); accessPermission.setType(AccessPermission.Type.WRITE_ENTRY); accessPermission.setTypeId(entry.getId()); permissionsController.addPermission(userId, accessPermission); } } return entry.getId(); }
/** * Moves the specified list of entries to the deleted folder * * @param userId unique identifier for user making the request. Must have write access privileges * on the entries in the list * @param list unique identifiers for entries * @return true or false if operation succeeds on all listed entries or not */ public boolean moveEntriesToTrash(String userId, ArrayList<PartData> list) { List<Entry> toTrash = new LinkedList<>(); for (PartData data : list) { Entry entry = dao.get(data.getId()); if (entry == null || !authorization.canWriteThoroughCheck(userId, entry)) return false; toTrash.add(entry); } // add to bin try { for (Entry entry : toTrash) { entry.setVisibility(Visibility.DELETED.getValue()); dao.update(entry); } } catch (DAOException de) { Logger.error(de); return false; } return true; }