DocumentManagerBean implements IDocumentManagerLocal { @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override public DocumentRevision updateDocument(DocumentIterationKey iKey, String pRevisionNote, List<InstanceAttribute> pAttributes, DocumentRevisionKey[] pLinkKeys, String[] documentLinkComments) throws WorkspaceNotFoundException, NotAllowedException, DocumentRevisionNotFoundException, AccessRightException, UserNotFoundException, UserNotActiveException, WorkspaceNotEnabledException { DocumentRevisionKey rKey = new DocumentRevisionKey(iKey.getWorkspaceId(), iKey.getDocumentMasterId(), iKey.getDocumentRevisionVersion()); User user = checkDocumentRevisionWriteAccess(rKey); DocumentRevision docR = documentRevisionDAO.loadDocR(rKey); if (isCheckoutByUser(user, docR) && docR.getLastIteration().getKey().equals(iKey)) { DocumentIteration doc = docR.getLastIteration(); if (pLinkKeys != null) { Set<DocumentLink> currentLinks = new HashSet<>(doc.getLinkedDocuments()); for (DocumentLink link : currentLinks) { doc.getLinkedDocuments().remove(link); } int counter = 0; for (DocumentRevisionKey link : pLinkKeys) { if (!link.equals(iKey.getDocumentRevision())) { DocumentLink newLink = new DocumentLink(documentRevisionDAO.loadDocR(link)); newLink.setComment(documentLinkComments[counter]); documentLinkDAO.createLink(newLink); doc.getLinkedDocuments().add(newLink); counter++; } } } if (pAttributes != null) { List<InstanceAttribute> currentAttrs = doc.getInstanceAttributes(); boolean valid = AttributesConsistencyUtils.hasValidChange(pAttributes, docR.isAttributesLocked(), currentAttrs); if (!valid) { throw new NotAllowedException("NotAllowedException59"); } doc.setInstanceAttributes(pAttributes); } doc.setRevisionNote(pRevisionNote); Date now = new Date(); doc.setModificationDate(now); return docR; } else { throw new NotAllowedException("NotAllowedException25"); } }  @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override BinaryResource saveFileInTemplate(DocumentMasterTemplateKey pDocMTemplateKey, String pName, long pSize); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override BinaryResource saveFileInDocument(DocumentIterationKey pDocPK, String pName, long pSize); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override void setDocumentPublicShared(DocumentRevisionKey pDocRPK, boolean isPublicShared); @LogDocument @RolesAllowed({UserGroupMapping.REGULAR_USER_ROLE_ID}) @Override BinaryResource getBinaryResource(String pFullName); @RolesAllowed({UserGroupMapping.REGULAR_USER_ROLE_ID}) @Override BinaryResource getTemplateBinaryResource(String pFullName); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override String[] getFolders(String pCompletePath); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override DocumentRevision[] findDocumentRevisionsByFolder(String pCompletePath); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override DocumentRevision[] findDocumentRevisionsByTag(TagKey pKey); @RolesAllowed({UserGroupMapping.REGULAR_USER_ROLE_ID}) @Override DocumentRevision getDocumentRevision(DocumentRevisionKey pDocRPK); @RolesAllowed({UserGroupMapping.REGULAR_USER_ROLE_ID}) @Override DocumentIteration findDocumentIterationByBinaryResource(BinaryResource pBinaryResource); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override void updateDocumentACL(String pWorkspaceId, DocumentRevisionKey docKey, Map<String, String> pACLUserEntries, Map<String, String> pACLUserGroupEntries); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override void updateACLForDocumentMasterTemplate(String pWorkspaceId, String pDocMTemplateId, Map<String, String> userEntries, Map<String, String> userGroupEntries); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override void removeACLFromDocumentRevision(DocumentRevisionKey documentRevisionKey); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override void removeACLFromDocumentMasterTemplate(String pWorkspaceId, String documentTemplateId); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override DocumentRevision[] getAllDocumentsInWorkspace(String workspaceId); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override DocumentRevision[] getFilteredDocumentsInWorkspace(String workspaceId, int start, int pMaxResults); @RolesAllowed({UserGroupMapping.REGULAR_USER_ROLE_ID, UserGroupMapping.ADMIN_ROLE_ID}) @Override int getDocumentsInWorkspaceCount(String workspaceId); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override DocumentRevision[] getCheckedOutDocumentRevisions(String pWorkspaceId); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override Task[] getTasks(String pWorkspaceId); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override DocumentRevisionKey[] getIterationChangeEventSubscriptions(String pWorkspaceId); @RolesAllowed({UserGroupMapping.REGULAR_USER_ROLE_ID}) @Override DocumentRevisionKey[] getStateChangeEventSubscriptions(String pWorkspaceId); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override boolean isUserStateChangeEventSubscribedForGivenDocument(String pWorkspaceId, DocumentRevision docR); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override boolean isUserIterationChangeEventSubscribedForGivenDocument(String pWorkspaceId, DocumentRevision docR); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override DocumentRevision[] getDocumentRevisionsWithReferenceOrTitle(String pWorkspaceId, String search, int maxResults); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override String generateId(String pWorkspaceId, String pDocMTemplateId); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override DocumentRevision[] searchDocumentRevisions(DocumentSearchQuery pQuery, int from, int size); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override DocumentMasterTemplate[] getDocumentMasterTemplates(String pWorkspaceId); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override DocumentMasterTemplate getDocumentMasterTemplate(DocumentMasterTemplateKey pKey); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override DocumentMasterTemplate updateDocumentMasterTemplate(DocumentMasterTemplateKey pKey, String pDocumentType, String pWorkflowModelId, String pMask, List<InstanceAttributeTemplate> pAttributeTemplates, String[] lovNames, boolean idGenerated, boolean attributesLocked); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override void deleteTag(TagKey pKey); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override void createTag(String pWorkspaceId, String pLabel); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override DocumentRevision createDocumentMaster(String pParentFolder, String pDocMId, String pTitle, String pDescription, String pDocMTemplateId, String pWorkflowModelId, Map<String, String> aclUserEntries, Map<String, String> aclGroupEntries, Map<String, Collection<String>> userRoleMapping, Map<String, Collection<String>> groupRoleMapping); @RolesAllowed({UserGroupMapping.REGULAR_USER_ROLE_ID, UserGroupMapping.ADMIN_ROLE_ID}) @Override DocumentRevision[] getAllCheckedOutDocumentRevisions(String pWorkspaceId); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override DocumentMasterTemplate createDocumentMasterTemplate(String pWorkspaceId, String pId, String pDocumentType, String pWorkflowModelId,
                                                               String pMask, List<InstanceAttributeTemplate> pAttributeTemplates, String[] lovNames, boolean idGenerated, boolean attributesLocked); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override DocumentRevision moveDocumentRevision(String pParentFolder, DocumentRevisionKey pDocRPK); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override Folder createFolder(String pParentFolder, String pFolder); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override DocumentRevision checkOutDocument(DocumentRevisionKey pDocRPK); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override DocumentRevision saveTags(DocumentRevisionKey pDocRPK, String[] pTags); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override DocumentRevision removeTag(DocumentRevisionKey pDocRPK, String pTag); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override DocumentRevision undoCheckOutDocument(DocumentRevisionKey pDocRPK); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override DocumentRevision checkInDocument(DocumentRevisionKey pDocRPK); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override DocumentRevisionKey[] deleteFolder(String pCompletePath); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override DocumentRevisionKey[] deleteUserFolder(User pUser); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override DocumentRevisionKey[] moveFolder(String pCompletePath, String pDestParentFolder, String pDestFolder); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override void deleteDocumentRevision(DocumentRevisionKey pDocRPK); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override void deleteDocumentMasterTemplate(DocumentMasterTemplateKey pKey); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override DocumentRevision removeFileFromDocument(String pFullName); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override BinaryResource renameFileInDocument(String pFullName, String pNewName); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override DocumentMasterTemplate removeFileFromTemplate(String pFullName); @Override BinaryResource renameFileInTemplate(String pFullName, String pNewName); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override DocumentRevision updateDocument(DocumentIterationKey iKey, String pRevisionNote, List<InstanceAttribute> pAttributes, DocumentRevisionKey[] pLinkKeys, String[] documentLinkComments); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override DocumentRevision[] createDocumentRevision(DocumentRevisionKey pOriginalDocRPK, String pTitle, String pDescription, String pWorkflowModelId, Map<String, String> aclUserEntries, Map<String, String> aclGroupEntries, Map<String, Collection<String>> userRoleMapping, Map<String, Collection<String>> groupRoleMapping); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override void subscribeToStateChangeEvent(DocumentRevisionKey pDocRPK); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override void unsubscribeToStateChangeEvent(DocumentRevisionKey pDocRPK); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override void subscribeToIterationChangeEvent(DocumentRevisionKey pDocRPK); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override void unsubscribeToIterationChangeEvent(DocumentRevisionKey pDocRPK); @RolesAllowed({UserGroupMapping.REGULAR_USER_ROLE_ID, UserGroupMapping.ADMIN_ROLE_ID}) @Override String[] getTags(String pWorkspaceId); @RolesAllowed({UserGroupMapping.REGULAR_USER_ROLE_ID, UserGroupMapping.ADMIN_ROLE_ID}) @Override long getDiskUsageForDocumentsInWorkspace(String pWorkspaceId); @RolesAllowed({UserGroupMapping.REGULAR_USER_ROLE_ID, UserGroupMapping.ADMIN_ROLE_ID}) @Override long getDiskUsageForDocumentTemplatesInWorkspace(String pWorkspaceId); @RolesAllowed({UserGroupMapping.REGULAR_USER_ROLE_ID}) @Override SharedDocument createSharedDocument(DocumentRevisionKey pDocRPK, String pPassword, Date pExpireDate); @RolesAllowed({UserGroupMapping.REGULAR_USER_ROLE_ID}) @Override void deleteSharedDocument(SharedEntityKey sharedEntityKey); @RolesAllowed({UserGroupMapping.REGULAR_USER_ROLE_ID, UserGroupMapping.ADMIN_ROLE_ID}) @Override boolean canAccess(DocumentRevisionKey docRKey); @RolesAllowed({UserGroupMapping.REGULAR_USER_ROLE_ID, UserGroupMapping.ADMIN_ROLE_ID}) @Override boolean canAccess(DocumentIterationKey docIKey); @RolesAllowed({UserGroupMapping.REGULAR_USER_ROLE_ID, UserGroupMapping.ADMIN_ROLE_ID}) @Override boolean canUserAccess(User user, DocumentRevisionKey docRKey); @RolesAllowed({UserGroupMapping.REGULAR_USER_ROLE_ID, UserGroupMapping.ADMIN_ROLE_ID}) @Override boolean canUserAccess(User user, DocumentIterationKey docIKey); @RolesAllowed({UserGroupMapping.REGULAR_USER_ROLE_ID}) @Override List<DocumentIteration> getInverseDocumentsLink(DocumentRevisionKey docKey); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override DocumentRevision[] getDocumentRevisionsWithAssignedTasksForGivenUser(String pWorkspaceId, String assignedUserLogin); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override DocumentRevision[] getDocumentRevisionsWithOpenedTasksForGivenUser(String pWorkspaceId, String assignedUserLogin); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override void createDocumentLog(DocumentLog log); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override DocumentRevision releaseDocumentRevision(DocumentRevisionKey pRevisionKey); @RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override DocumentRevision markDocumentRevisionAsObsolete(DocumentRevisionKey pRevisionKey); @Override void logDocument(String fullName, String event);  }
@Test public void changeAttributesWithLockedTemplate() throws Exception { DocumentMaster documentMaster = new DocumentMaster(workspace, DocumentUtil.DOCUMENT_ID, user); documentRevision = new DocumentRevision(documentMaster, "A", user); documentIteration = new DocumentIteration(documentRevision, user); documentRevision.setCheckOutUser(user); documentRevision.setCheckOutDate(new Date()); ArrayList<DocumentIteration> iterations = new ArrayList<>(); iterations.add(documentIteration); documentRevision.setDocumentIterations(iterations); DocumentRevisionKey documentRevisionKey = new DocumentRevisionKey(workspace.getId(), documentMaster.getId(), documentRevision.getVersion()); InstanceAttribute attribute = new InstanceTextAttribute("Nom", "Testeur", false); List<InstanceAttribute> attributesOfIteration = new ArrayList<>(); attributesOfIteration.add(attribute); documentIteration.setInstanceAttributes(attributesOfIteration); documentMaster.setAttributesLocked(true); Mockito.when(userManager.checkWorkspaceReadAccess(workspace.getId())).thenReturn(user); Mockito.when(userManager.checkWorkspaceWriteAccess(workspace.getId())).thenReturn(user); Mockito.when(documentRevisionDAO.loadDocR(documentRevisionKey)).thenReturn(documentRevision); try { documentManagerBean.updateDocument(documentIteration.getKey(), "test", Arrays.asList(new InstanceAttribute[]{}), new DocumentRevisionKey[]{}, null); Assert.fail("updateDocument should have raise an exception because we have removed attributes"); } catch (NotAllowedException notAllowedException) { try { documentManagerBean.updateDocument(documentIteration.getKey(), "test", Arrays.asList(new InstanceAttribute[]{new InstanceDateAttribute("Nom", new Date(), false)}), new DocumentRevisionKey[]{}, null); Assert.fail("updateDocument should have raise an exception because we have changed the attribute type attributes"); } catch (NotAllowedException notAllowedException2) { try { documentManagerBean.updateDocument(documentIteration.getKey(), "test", Arrays.asList(new InstanceAttribute[]{attribute}), new DocumentRevisionKey[]{}, null); documentManagerBean.updateDocument(documentIteration.getKey(), "test", Arrays.asList(new InstanceAttribute[]{new InstanceTextAttribute("Nom", "Testeur change", false)}), new DocumentRevisionKey[]{}, null); } catch (NotAllowedException notAllowedException3) { Assert.fail("updateDocument shouldn't have raised an exception because we haven't change the number of attribute or the type"); } } } }
@Test public void changeAttributesWithUnlockedTemplate() throws Exception { DocumentMaster documentMaster = new DocumentMaster(workspace, DocumentUtil.DOCUMENT_ID, user); documentRevision = new DocumentRevision(documentMaster, "A", user); documentIteration = new DocumentIteration(documentRevision, user); documentRevision.setCheckOutUser(user); documentRevision.setCheckOutDate(new Date()); ArrayList<DocumentIteration> iterations = new ArrayList<>(); iterations.add(documentIteration); documentRevision.setDocumentIterations(iterations); DocumentRevisionKey documentRevisionKey = new DocumentRevisionKey(workspace.getId(), documentMaster.getId(), documentRevision.getVersion()); InstanceAttribute attribute = new InstanceTextAttribute("Nom", "Testeur", false); List<InstanceAttribute> attributesOfIteration = new ArrayList<>(); attributesOfIteration.add(attribute); documentIteration.setInstanceAttributes(attributesOfIteration); documentMaster.setAttributesLocked(false); Mockito.when(userManager.checkWorkspaceReadAccess(workspace.getId())).thenReturn(user); Mockito.when(userManager.checkWorkspaceWriteAccess(workspace.getId())).thenReturn(user); Mockito.when(documentRevisionDAO.loadDocR(documentRevisionKey)).thenReturn(documentRevision); try { documentManagerBean.updateDocument(documentIteration.getKey(), "test", Arrays.asList(new InstanceAttribute[]{}), new DocumentRevisionKey[]{}, null); documentManagerBean.updateDocument(documentIteration.getKey(), "test", Arrays.asList(new InstanceAttribute[]{attribute}), new DocumentRevisionKey[]{}, null); documentManagerBean.updateDocument(documentIteration.getKey(), "test", Arrays.asList(new InstanceAttribute[]{new InstanceTextAttribute("Nom", "Testeur change", false)}), new DocumentRevisionKey[]{}, null); documentManagerBean.updateDocument(documentIteration.getKey(), "test", Arrays.asList(new InstanceAttribute[]{new InstanceDateAttribute("Nom", new Date(), false)}), new DocumentRevisionKey[]{}, null); } catch (NotAllowedException notAllowedException3) { Assert.fail("updateDocument shouldn't have raised an exception because the attribute are not frozen"); } }