private Content checkExceptionBeforeUpdateProperties( CallContext callContext, String repositoryId, Holder<String> objectId, Properties properties, Holder<String> changeToken) { // ////////////////// // General Exception // ////////////////// exceptionService.invalidArgumentRequiredCollection("properties", properties.getPropertyList()); Content content = contentService.getContent(repositoryId, objectId.getValue()); exceptionService.objectNotFound(DomainType.OBJECT, content, objectId.getValue()); if (content.isDocument()) { Document d = (Document) content; exceptionService.versioning(d); exceptionService.constraintUpdateWhenCheckedOut(repositoryId, callContext.getUsername(), d); TypeDefinition typeDef = typeManager.getTypeDefinition(repositoryId, d); exceptionService.constraintImmutable(repositoryId, d, typeDef); } exceptionService.permissionDenied( callContext, repositoryId, PermissionMapping.CAN_UPDATE_PROPERTIES_OBJECT, content); exceptionService.updateConflict(content, changeToken); TypeDefinition tdf = typeManager.getTypeDefinition(repositoryId, content); exceptionService.constraintPropertyValue(repositoryId, tdf, properties, objectId.getValue()); return content; }
@Override public String createDocumentFromSource( CallContext callContext, String repositoryId, String sourceId, Properties properties, String folderId, VersioningState versioningState, List<String> policies, Acl addAces, Acl removeAces) { Document original = contentService.getDocument(repositoryId, sourceId); DocumentTypeDefinition td = (DocumentTypeDefinition) typeManager.getTypeDefinition(repositoryId, original.getObjectType()); // ////////////////// // General Exception // ////////////////// exceptionService.invalidArgumentRequired("properties", properties); exceptionService.invalidArgumentRequiredParentFolderId(repositoryId, folderId); Folder parentFolder = contentService.getFolder(repositoryId, folderId); exceptionService.objectNotFoundParentFolder(repositoryId, folderId, parentFolder); exceptionService.permissionDenied( callContext, repositoryId, PermissionMapping.CAN_CREATE_FOLDER_FOLDER, parentFolder); // ////////////////// // Specific Exception // ////////////////// exceptionService.constraintBaseTypeId(repositoryId, properties, BaseTypeId.CMIS_DOCUMENT); exceptionService.constraintAllowedChildObjectTypeId(parentFolder, properties); exceptionService.constraintPropertyValue( repositoryId, td, properties, DataUtil.getIdProperty(properties, PropertyIds.OBJECT_ID)); exceptionService.constraintControllableVersionable(td, versioningState, null); versioningState = (td.isVersionable() && versioningState == null) ? VersioningState.MAJOR : versioningState; exceptionService.constraintCotrollablePolicies(td, policies, properties); exceptionService.constraintCotrollableAcl(td, addAces, removeAces, properties); exceptionService.constraintPermissionDefined(repositoryId, addAces, null); exceptionService.constraintPermissionDefined(repositoryId, removeAces, null); exceptionService.nameConstraintViolation(properties, parentFolder); // ////////////////// // Body of the method // ////////////////// Document document = contentService.createDocumentFromSource( callContext, repositoryId, properties, parentFolder, original, versioningState, policies, addAces, removeAces); return document.getId(); }
@Override public void setContentStream( CallContext callContext, String repositoryId, Holder<String> objectId, boolean overwriteFlag, ContentStream contentStream, Holder<String> changeToken) { exceptionService.invalidArgumentRequiredHolderString("objectId", objectId); Lock lock = threadLockService.getWriteLock(repositoryId, objectId.getValue()); try { lock.lock(); // ////////////////// // General Exception // ////////////////// exceptionService.invalidArgumentRequired("contentStream", contentStream); Document doc = (Document) contentService.getContent(repositoryId, objectId.getValue()); exceptionService.objectNotFound(DomainType.OBJECT, doc, objectId.getValue()); exceptionService.permissionDenied( callContext, repositoryId, PermissionMapping.CAN_SET_CONTENT_DOCUMENT, doc); DocumentTypeDefinition td = (DocumentTypeDefinition) typeManager.getTypeDefinition(repositoryId, doc.getObjectType()); exceptionService.constraintImmutable(repositoryId, doc, td); // ////////////////// // Specific Exception // ////////////////// exceptionService.contentAlreadyExists(doc, overwriteFlag); exceptionService.streamNotSupported(td, contentStream); exceptionService.updateConflict(doc, changeToken); exceptionService.versioning(doc); Folder parent = contentService.getParent(repositoryId, objectId.getValue()); exceptionService.objectNotFoundParentFolder(repositoryId, objectId.getValue(), parent); // ////////////////// // Body of the method // ////////////////// String oldId = objectId.getValue(); // TODO Externalize versioningState if (doc.isPrivateWorkingCopy()) { Document result = contentService.replacePwc(callContext, repositoryId, doc, contentStream); objectId.setValue(result.getId()); } else { Document result = contentService.createDocumentWithNewStream( callContext, repositoryId, doc, contentStream); objectId.setValue(result.getId()); } nemakiCachePool.get(repositoryId).removeCmisCache(oldId); } finally { lock.unlock(); } }
@Override public void constraintVersionable(String repositoryId, String typeId) { DocumentTypeDefinition type = (DocumentTypeDefinition) typeManager.getTypeDefinition(repositoryId, typeId); if (!type.isVersionable()) { String msg = "Object type: " + type.getId() + " is not versionbale"; throw new CmisConstraintException(msg, HTTP_STATUS_CODE_409); } }
@Override public void constraintBaseTypeId( String repositoryId, Properties properties, BaseTypeId baseTypeId) { String objectTypeId = DataUtil.getObjectTypeId(properties); TypeDefinition td = typeManager.getTypeDefinition(repositoryId, objectTypeId); if (!td.getBaseTypeId().equals(baseTypeId)) constraint(null, "cmis:objectTypeId is not an object type whose base tyep is " + baseTypeId); }
@Override public void invalidArgumentDoesNotExistType(String repositoryId, String typeId) { String msg = ""; TypeDefinition type = typeManager.getTypeDefinition(repositoryId, typeId); if (type == null) { msg = "Specified type does not exist"; msg = msg + " [objectTypeId = " + typeId + "]"; invalidArgument(msg); } }
@Override public void constraintOnlyLeafTypeDefinition(String repositoryId, String objectTypeId) { TypeDefinitionContainer tdc = typeManager.getTypeById(repositoryId, objectTypeId); if (!CollectionUtils.isEmpty(tdc.getChildren())) { String msg = "Cannot delete a type definition which has sub types" + " [objectTypeId = " + objectTypeId + "]"; throw new CmisConstraintException(msg, HTTP_STATUS_CODE_409); } }
@Override public void constraintContentStreamRequired(String repositoryId, Document document) { String objectTypeId = document.getObjectType(); DocumentTypeDefinition td = (DocumentTypeDefinition) typeManager.getTypeDefinition(repositoryId, objectTypeId); if (td.getContentStreamAllowed() == ContentStreamAllowed.REQUIRED) { if (document.getAttachmentNodeId() == null || contentService.getAttachment(repositoryId, document.getAttachmentNodeId()) == null) { constraint(document.getId(), "This document type does not allow no content stream"); } } }
@Override public void constraintContentStreamDownload(String repositoryId, Document document) { DocumentTypeDefinition documentTypeDefinition = (DocumentTypeDefinition) typeManager.getTypeDefinition(repositoryId, document); ContentStreamAllowed csa = documentTypeDefinition.getContentStreamAllowed(); if (ContentStreamAllowed.NOTALLOWED == csa || ContentStreamAllowed.ALLOWED == csa && StringUtils.isBlank(document.getAttachmentNodeId())) { constraint( document.getId(), "This document has no ContentStream. getContentStream is not supported."); } }
@Override public void invalidArgumentDeletableType(String repositoryId, String typeId) { TypeDefinition type = typeManager.getTypeDefinition(repositoryId, typeId); String msg = ""; TypeMutability typeMutability = type.getTypeMutability(); boolean canUpdate = (typeMutability.canDelete() == null) ? true : typeMutability.canDelete(); if (!canUpdate) { msg = "Specified type is not deletable"; msg = msg + " [objectTypeId = " + type.getId() + "]"; invalidArgument(msg); } }
@Override public String createRelationship( CallContext callContext, String repositoryId, Properties properties, List<String> policies, Acl addAces, Acl removeAces, ExtensionsData extension) { String objectTypeId = DataUtil.getIdProperty(properties, PropertyIds.OBJECT_TYPE_ID); RelationshipTypeDefinition td = (RelationshipTypeDefinition) typeManager.getTypeDefinition(repositoryId, objectTypeId); // ////////////////// // Exception // ////////////////// exceptionService.invalidArgumentRequiredCollection("properties", properties.getPropertyList()); String sourceId = DataUtil.getIdProperty(properties, PropertyIds.SOURCE_ID); if (sourceId != null) { Content source = contentService.getContent(repositoryId, sourceId); if (source == null) exceptionService.constraintAllowedSourceTypes(td, source); exceptionService.permissionDenied( callContext, repositoryId, PermissionMapping.CAN_CREATE_RELATIONSHIP_SOURCE, source); } String targetId = DataUtil.getIdProperty(properties, PropertyIds.TARGET_ID); if (targetId != null) { Content target = contentService.getContent(repositoryId, targetId); if (target == null) exceptionService.constraintAllowedTargetTypes(td, target); exceptionService.permissionDenied( callContext, repositoryId, PermissionMapping.CAN_CREATE_RELATIONSHIP_TARGET, target); } exceptionService.constraintBaseTypeId(repositoryId, properties, BaseTypeId.CMIS_RELATIONSHIP); exceptionService.constraintPropertyValue( repositoryId, td, properties, DataUtil.getIdProperty(properties, PropertyIds.OBJECT_ID)); exceptionService.constraintCotrollablePolicies(td, policies, properties); exceptionService.constraintCotrollableAcl(td, addAces, removeAces, properties); exceptionService.constraintPermissionDefined(repositoryId, addAces, null); exceptionService.constraintPermissionDefined(repositoryId, removeAces, null); exceptionService.nameConstraintViolation(properties, null); // ////////////////// // Body of the method // ////////////////// Relationship relationship = contentService.createRelationship( callContext, repositoryId, properties, policies, addAces, removeAces, extension); nemakiCachePool.get(repositoryId).removeCmisCache(relationship.getSourceId()); nemakiCachePool.get(repositoryId).removeCmisCache(relationship.getTargetId()); return relationship.getId(); }
@Override public <T> void constraintPropertyValue( String repositoryId, TypeDefinition typeDefinition, Properties properties, String objectId) { Map<String, PropertyDefinition<?>> propertyDefinitions = typeDefinition.getPropertyDefinitions(); // Adding secondary types and its properties MAY be done in the same // operation List<String> secIds = DataUtil.getIdListProperty(properties, PropertyIds.SECONDARY_OBJECT_TYPE_IDS); if (CollectionUtils.isNotEmpty(secIds)) { for (String secId : secIds) { TypeDefinition sec = typeManager.getTypeById(repositoryId, secId).getTypeDefinition(); for (Entry<String, PropertyDefinition<?>> entry : sec.getPropertyDefinitions().entrySet()) { if (!propertyDefinitions.containsKey(entry.getKey())) { propertyDefinitions.put(entry.getKey(), entry.getValue()); } } } } for (PropertyData<?> _pd : properties.getPropertyList()) { PropertyData<T> pd = (PropertyData<T>) _pd; PropertyDefinition<T> propertyDefinition = (PropertyDefinition<T>) propertyDefinitions.get(pd.getId()); // If an input property is not defined one, output error. if (propertyDefinition == null) constraint(objectId, "An undefined property is provided!"); // Check "required" flag if (propertyDefinition.isRequired() && !DataUtil.valueExist(pd.getValues())) constraint(objectId, "An required property is not provided!"); // Check choices constraintChoices(propertyDefinition, pd, objectId); // Check min/max length switch (propertyDefinition.getPropertyType()) { case STRING: constraintStringPropertyValue(propertyDefinition, pd, objectId); break; case DECIMAL: constraintDecimalPropertyValue(propertyDefinition, pd, objectId); case INTEGER: constraintIntegerPropertyValue(propertyDefinition, pd, objectId); break; default: break; } } }
@Override public void invalidArgumentCreatableType(String repositoryId, TypeDefinition type) { String msg = ""; String parentId = type.getParentTypeId(); if (typeManager.getTypeById(repositoryId, parentId) == null) { msg = "Specified parent type does not exist"; } else { TypeDefinition parent = typeManager.getTypeById(repositoryId, parentId).getTypeDefinition(); if (parent.getTypeMutability() == null) { msg = "Specified parent type does not have TypeMutability"; } else { boolean canCreate = (parent.getTypeMutability() == null) ? false : true; if (!canCreate) { msg = "Specified parent type has TypeMutability.canCreate = false"; } } } if (!StringUtils.isEmpty(msg)) { msg = msg + " [objectTypeId = " + type.getId() + "]"; invalidArgument(msg); } }
@Override public void appendContentStream( CallContext callContext, String repositoryId, Holder<String> objectId, Holder<String> changeToken, ContentStream contentStream, boolean isLastChunk, ExtensionsData extension) { exceptionService.invalidArgumentRequiredHolderString("objectId", objectId); Lock lock = threadLockService.getWriteLock(repositoryId, objectId.getValue()); try { lock.lock(); // ////////////////// // General Exception // ////////////////// exceptionService.invalidArgumentRequired("contentStream", contentStream); Document doc = (Document) contentService.getContent(repositoryId, objectId.getValue()); exceptionService.objectNotFound(DomainType.OBJECT, doc, objectId.getValue()); exceptionService.permissionDenied( callContext, repositoryId, PermissionMapping.CAN_SET_CONTENT_DOCUMENT, doc); DocumentTypeDefinition td = (DocumentTypeDefinition) typeManager.getTypeDefinition(repositoryId, doc.getObjectType()); exceptionService.constraintImmutable(repositoryId, doc, td); // ////////////////// // Specific Exception // ////////////////// exceptionService.streamNotSupported(td, contentStream); exceptionService.updateConflict(doc, changeToken); exceptionService.versioning(doc); // ////////////////// // Body of the method // ////////////////// contentService.appendAttachment( callContext, repositoryId, objectId, changeToken, contentStream, isLastChunk, extension); nemakiCachePool.get(repositoryId).removeCmisCache(objectId.getValue()); } finally { lock.unlock(); } }
@Override public String createItem( CallContext callContext, String repositoryId, Properties properties, String folderId, List<String> policies, Acl addAces, Acl removeAces, ExtensionsData extension) { // ////////////////// // General Exception // ////////////////// TypeDefinition td = typeManager.getTypeDefinition(repositoryId, DataUtil.getObjectTypeId(properties)); Folder parentFolder = contentService.getFolder(repositoryId, folderId); exceptionService.objectNotFoundParentFolder(repositoryId, folderId, parentFolder); exceptionService.invalidArgumentRequiredCollection("properties", properties.getPropertyList()); // ////////////////// // Specific Exception // ////////////////// exceptionService.constraintBaseTypeId(repositoryId, properties, BaseTypeId.CMIS_ITEM); exceptionService.constraintPropertyValue( repositoryId, td, properties, DataUtil.getIdProperty(properties, PropertyIds.OBJECT_ID)); exceptionService.constraintCotrollablePolicies(td, policies, properties); exceptionService.constraintCotrollableAcl(td, addAces, removeAces, properties); // ////////////////// // Body of the method // ////////////////// Item item = contentService.createItem( callContext, repositoryId, properties, folderId, policies, addAces, removeAces, extension); return item.getId(); }
@Override public String createFolder( CallContext callContext, String repositoryId, Properties properties, String folderId, List<String> policies, Acl addAces, Acl removeAces, ExtensionsData extension) { FolderTypeDefinition td = (FolderTypeDefinition) typeManager.getTypeDefinition(repositoryId, DataUtil.getObjectTypeId(properties)); Folder parentFolder = contentService.getFolder(repositoryId, folderId); // ////////////////// // General Exception // ////////////////// exceptionService.objectNotFoundParentFolder(repositoryId, folderId, parentFolder); exceptionService.permissionDenied( callContext, repositoryId, PermissionMapping.CAN_CREATE_FOLDER_FOLDER, parentFolder); // ////////////////// // Specific Exception // ////////////////// exceptionService.constraintBaseTypeId(repositoryId, properties, BaseTypeId.CMIS_FOLDER); exceptionService.constraintAllowedChildObjectTypeId(parentFolder, properties); exceptionService.constraintPropertyValue( repositoryId, td, properties, DataUtil.getIdProperty(properties, PropertyIds.OBJECT_ID)); exceptionService.constraintCotrollablePolicies(td, policies, properties); exceptionService.constraintCotrollableAcl(td, addAces, removeAces, properties); exceptionService.constraintPermissionDefined(repositoryId, addAces, null); exceptionService.constraintPermissionDefined(repositoryId, removeAces, null); exceptionService.nameConstraintViolation(properties, parentFolder); // ////////////////// // Body of the method // ////////////////// Folder folder = contentService.createFolder(callContext, repositoryId, properties, parentFolder); return folder.getId(); }
private <T> PropertyDefinition<T> constraintUpdatePropertyDefinitionHelper( PropertyDefinition<T> update, PropertyDefinition<?> old) { String msg = ""; // objField.setName(field.getName()); // objField.setValue(field.getValue()); // return objField; if (!old.isInherited().equals(update.isInherited())) { msg += "'inherited' cannot be modified"; } if (typeManager.getSystemPropertyIds().contains(update.getId())) { msg += "CMIS-defined property definition cannot be modified"; } if (Boolean.FALSE.equals(old.isRequired()) && Boolean.TRUE.equals(update.isRequired())) { msg += "'required' cannot be modified from Optional to Required"; constraint(msg); } if (Boolean.TRUE.equals(old.isOpenChoice()) && Boolean.FALSE.equals(update.isOpenChoice())) { msg += "'openChoice' cannot be modified from true to false"; constraint(msg); } if (Boolean.FALSE.equals(update.isOpenChoice())) { constraintChoicesRestriction(update, old); } constraintRestrictedValidation(update, old); if (!old.getPropertyType().equals(update.getPropertyType())) { msg += "'property type' cannot be modified"; constraint(msg); } if (!old.getCardinality().equals(update.getCardinality())) { msg += "'cardinality' cannot be modified"; constraint(msg); } return update; }
@Override public String createPolicy( CallContext callContext, String repositoryId, Properties properties, String folderId, List<String> policies, Acl addAces, Acl removeAces, ExtensionsData extension) { // ////////////////// // General Exception // ////////////////// exceptionService.invalidArgumentRequiredCollection("properties", properties.getPropertyList()); // NOTE: folderId is ignored because policy is not filable in Nemaki TypeDefinition td = typeManager.getTypeDefinition( repositoryId, DataUtil.getIdProperty(properties, PropertyIds.OBJECT_TYPE_ID)); exceptionService.constraintPropertyValue( repositoryId, td, properties, DataUtil.getIdProperty(properties, PropertyIds.OBJECT_ID)); // ////////////////// // Specific Exception // ////////////////// exceptionService.constraintBaseTypeId(repositoryId, properties, BaseTypeId.CMIS_POLICY); // exceptionService.constraintAllowedChildObjectTypeId(parent, // properties); exceptionService.constraintCotrollablePolicies(td, policies, properties); exceptionService.constraintCotrollableAcl(td, addAces, removeAces, properties); // exceptionService.nameConstraintViolation(properties, parent); // ////////////////// // Body of the method // ////////////////// Policy policy = contentService.createPolicy( callContext, repositoryId, properties, policies, addAces, removeAces, extension); return policy.getId(); }
@Override public void constraintImmutable( String repositoryId, Document document, TypeDefinition typeDefinition) { Boolean defaultVal = (Boolean) typeManager.getSingleDefaultValue( PropertyIds.IS_IMMUTABLE, typeDefinition.getId(), repositoryId); boolean flag = false; if (document.isImmutable() == null) { if (defaultVal != null && defaultVal) { flag = true; } } else { if (document.isImmutable()) { flag = true; } } if (flag) { constraint(document.getId(), "Immutable document cannot be updated/deleted"); } }
@Override public void invalidArgumentSecondaryTypeIds(String repositoryId, Properties properties) { if (properties == null) return; Map<String, PropertyData<?>> map = properties.getProperties(); if (MapUtils.isEmpty(map)) return; List<String> results = new ArrayList<String>(); PropertyData<?> ids = map.get(PropertyIds.SECONDARY_OBJECT_TYPE_IDS); if (ids == null || CollectionUtils.isEmpty(ids.getValues())) return; for (Object _id : ids.getValues()) { String id = (String) _id; TypeDefinitionContainer tdc = typeManager.getTypeById(repositoryId, id); if (tdc == null) { results.add(id); } } if (CollectionUtils.isNotEmpty(results)) { String msg = "Invalid cmis:SecondaryObjectTypeIds are provided:" + StringUtils.join(results, ","); invalidArgument(msg); } }
@Override public void constraintDuplicatePropertyDefinition( String repositoryId, TypeDefinition typeDefinition) { Map<String, PropertyDefinition<?>> props = typeDefinition.getPropertyDefinitions(); if (MapUtils.isNotEmpty(props)) { Set<String> keys = props.keySet(); TypeDefinition parent = typeManager.getTypeDefinition(repositoryId, typeDefinition.getParentTypeId()); Map<String, PropertyDefinition<?>> parentProps = parent.getPropertyDefinitions(); if (MapUtils.isNotEmpty(parentProps)) { Set<String> parentKeys = parentProps.keySet(); for (String key : keys) { if (parentKeys.contains(key)) { String msg = "Duplicate property definition with parent type definition" + " [property id = " + key + "]"; throw new CmisConstraintException(msg, HTTP_STATUS_CODE_409); } } } } }
@Override public ObjectData create( CallContext callContext, String repositoryId, Properties properties, String folderId, ContentStream contentStream, VersioningState versioningState, List<String> policies, ExtensionsData extension) { String typeId = DataUtil.getObjectTypeId(properties); TypeDefinition type = typeManager.getTypeDefinition(repositoryId, typeId); if (type == null) { throw new CmisObjectNotFoundException("Type '" + typeId + "' is unknown!"); } String objectId = null; // TODO ACE can be set ! if (type.getBaseTypeId() == BaseTypeId.CMIS_DOCUMENT) { objectId = createDocument( callContext, repositoryId, properties, folderId, contentStream, versioningState, null, null, null); } else if (type.getBaseTypeId() == BaseTypeId.CMIS_FOLDER) { objectId = createFolder( callContext, repositoryId, properties, folderId, policies, null, null, extension); } else if (type.getBaseTypeId() == BaseTypeId.CMIS_RELATIONSHIP) { objectId = createRelationship( callContext, repositoryId, properties, policies, null, null, extension); } else if (type.getBaseTypeId() == BaseTypeId.CMIS_POLICY) { objectId = createPolicy( callContext, repositoryId, properties, folderId, policies, null, null, extension); } else if (type.getBaseTypeId() == BaseTypeId.CMIS_ITEM) { objectId = createItem( callContext, repositoryId, properties, folderId, policies, null, null, extension); } else { throw new CmisObjectNotFoundException("Cannot create object of type '" + typeId + "'!"); } ObjectData object = compileService.compileObjectData( callContext, repositoryId, contentService.getContent(repositoryId, objectId), null, false, IncludeRelationships.NONE, null, false); return object; }