use of org.apache.chemistry.opencmis.commons.definitions.TypeDefinition in project copper-cms by PogeyanOSS.
the class RepositoryActor method getTypeDefinition.
private JSONObject getTypeDefinition(QueryGetRequest request) throws CmisRuntimeException, IllegalArgumentException {
String permission = request.getUserObject().getPermission();
if (!Helpers.checkingUserPremission(permission, "get")) {
throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
}
String typeId = request.getParameter(QueryGetRequest.PARAM_TYPE_ID);
DateTimeFormat dateTimeFormat = request.getDateTimeFormatParameter();
TypeDefinition type = CmisTypeServices.Impl.getTypeDefinition(request.getRepositoryId(), typeId, null);
JSONObject resultType = JSONConverter.convert(type, dateTimeFormat);
return resultType;
}
use of org.apache.chemistry.opencmis.commons.definitions.TypeDefinition in project copper-cms by PogeyanOSS.
the class CreateDocumentWithoutContent method run.
@Override
public void run(Session session) {
CmisTestResult f;
String objectTypeId = getDocumentTestTypeId();
TypeDefinition type = session.getTypeDefinition(objectTypeId);
if (!(type instanceof DocumentTypeDefinition)) {
addResult(createResult(FAILURE, "Type is not a document type! Type: " + objectTypeId, true));
return;
}
DocumentTypeDefinition docType = (DocumentTypeDefinition) type;
if (docType.getContentStreamAllowed() == ContentStreamAllowed.REQUIRED) {
addResult(createResult(SKIPPED, "The test document type does not support documents without content. Test skipped!"));
return;
}
// create a test folder
Folder testFolder = createTestFolder(session);
try {
String name = "nocontent";
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, name);
properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
VersioningState versioningState = (Boolean.TRUE.equals(docType.isVersionable()) ? VersioningState.MAJOR : VersioningState.NONE);
// create and fetch the document
ObjectId id = session.createDocument(properties, testFolder, null, versioningState);
Document doc = (Document) session.getObject(id, SELECT_ALL_NO_CACHE_OC);
// check the new document
addResult(checkObject(session, doc, getAllProperties(doc), "New document object spec compliance"));
// check the MIME type
f = createResult(FAILURE, "The document has no content but a MIME type!", true);
assertNull(doc.getContentStreamMimeType(), null, f);
// check the content size
if (doc.getContentStreamLength() == 0) {
addResult(createResult(WARNING, "The document has no content but the content length is set to 0! " + "The content length shouldn't be set."));
} else if (doc.getContentStreamLength() > 0) {
addResult(createResult(FAILURE, "The document has no content but the content length is set and >0! " + "(content length: " + doc.getContentStreamLength() + ")"));
}
// delete it
doc.delete(true);
} finally {
// delete the test folder
deleteTestFolder();
}
}
use of org.apache.chemistry.opencmis.commons.definitions.TypeDefinition in project copper-cms by PogeyanOSS.
the class BaseTypesTest method run.
@Override
public void run(Session session) {
CmisTestResult failure;
// check base types
Set<String> cmisTypes = new HashSet<String>();
cmisTypes.add(BaseTypeId.CMIS_DOCUMENT.value());
cmisTypes.add(BaseTypeId.CMIS_FOLDER.value());
cmisTypes.add(BaseTypeId.CMIS_RELATIONSHIP.value());
cmisTypes.add(BaseTypeId.CMIS_POLICY.value());
if (session.getRepositoryInfo().getCmisVersion() != CmisVersion.CMIS_1_0) {
cmisTypes.add(BaseTypeId.CMIS_ITEM.value());
cmisTypes.add(BaseTypeId.CMIS_SECONDARY.value());
}
for (TypeDefinition typeDef : session.getTypeChildren(null, false)) {
String typeId = typeDef.getId();
if (typeId == null || !cmisTypes.contains(typeId)) {
addResult(createResult(FAILURE, "Base type has an invalid ID: " + typeId));
}
if (typeDef.getPropertyDefinitions() != null && !typeDef.getPropertyDefinitions().isEmpty()) {
addResult(createResult(WARNING, "Property type definitions were not requested but delivered. Type ID: " + typeId));
}
}
// document
try {
TypeDefinition documentType = session.getTypeDefinition(BaseTypeId.CMIS_DOCUMENT.value());
addResult(checkTypeDefinition(session, documentType, "Document type spec compliance: " + documentType.getId()));
failure = createResult(FAILURE, "Document type has the wrong base type: " + documentType.getBaseTypeId());
addResult(assertEquals(BaseTypeId.CMIS_DOCUMENT, documentType.getBaseTypeId(), null, failure));
} catch (CmisObjectNotFoundException e) {
addResult(createResult(FAILURE, "Document type not available!", e, false));
}
// folder
try {
TypeDefinition folderType = session.getTypeDefinition(BaseTypeId.CMIS_FOLDER.value());
addResult(checkTypeDefinition(session, folderType, "Folder type spec compliance: " + folderType.getId()));
failure = createResult(FAILURE, "Folder type has the wrong base type: " + folderType.getBaseTypeId());
addResult(assertEquals(BaseTypeId.CMIS_FOLDER, folderType.getBaseTypeId(), null, failure));
} catch (CmisObjectNotFoundException e) {
addResult(createResult(FAILURE, "Folder type not available!", e, false));
}
// relationship
try {
TypeDefinition relationshipType = session.getTypeDefinition(BaseTypeId.CMIS_RELATIONSHIP.value());
addResult(checkTypeDefinition(session, relationshipType, "Relationship type spec compliance: " + relationshipType.getId()));
failure = createResult(FAILURE, "Relationship type has the wrong base type: " + relationshipType.getBaseTypeId());
addResult(assertEquals(BaseTypeId.CMIS_RELATIONSHIP, relationshipType.getBaseTypeId(), null, failure));
} catch (CmisObjectNotFoundException e) {
addResult(createResult(WARNING, "Relationship type not available!", e, false));
}
// policy
try {
TypeDefinition policyType = session.getTypeDefinition(BaseTypeId.CMIS_POLICY.value());
addResult(checkTypeDefinition(session, policyType, "Policy type spec compliance: " + policyType.getId()));
failure = createResult(FAILURE, "Policy type has the wrong base type: " + policyType.getBaseTypeId());
addResult(assertEquals(BaseTypeId.CMIS_POLICY, policyType.getBaseTypeId(), null, failure));
} catch (CmisInvalidArgumentException e) {
addResult(createResult(WARNING, "Policy type not available!", e, false));
} catch (CmisObjectNotFoundException e) {
addResult(createResult(WARNING, "Policy type not available!", e, false));
}
// CMIS 1.1 types
if (session.getRepositoryInfo().getCmisVersion() == CmisVersion.CMIS_1_1) {
// item
try {
TypeDefinition itemType = session.getTypeDefinition(BaseTypeId.CMIS_ITEM.value());
addResult(checkTypeDefinition(session, itemType, "Item type spec compliance: " + itemType.getId()));
failure = createResult(FAILURE, "Item type has the wrong base type: " + itemType.getBaseTypeId());
addResult(assertEquals(BaseTypeId.CMIS_ITEM, itemType.getBaseTypeId(), null, failure));
} catch (CmisInvalidArgumentException e) {
addResult(createResult(WARNING, "Item type not available!", e, false));
} catch (CmisObjectNotFoundException e) {
addResult(createResult(WARNING, "Item type not available!", e, false));
}
// secondary type
try {
TypeDefinition secondaryType = session.getTypeDefinition(BaseTypeId.CMIS_SECONDARY.value());
addResult(checkTypeDefinition(session, secondaryType, "Secondary type spec compliance: " + secondaryType.getId()));
failure = createResult(FAILURE, "Secondary type has the wrong base type: " + secondaryType.getBaseTypeId());
addResult(assertEquals(BaseTypeId.CMIS_SECONDARY, secondaryType.getBaseTypeId(), null, failure));
} catch (CmisInvalidArgumentException e) {
addResult(createResult(WARNING, "Secondary type not available!", e, false));
} catch (CmisObjectNotFoundException e) {
addResult(createResult(WARNING, "Secondary type not available!", e, false));
}
} else {
try {
session.getTypeDefinition(BaseTypeId.CMIS_ITEM.value());
addResult(createResult(FAILURE, "CMIS 1.0 repository returns cmis:item type definition!"));
} catch (CmisBaseException e) {
// expected
}
try {
session.getTypeDefinition(BaseTypeId.CMIS_SECONDARY.value());
addResult(createResult(FAILURE, "CMIS 1.0 repository returns cmis:secondary type definition!"));
} catch (CmisBaseException e) {
// expected
}
}
// simple getTypeChildren paging test - skipping over all base types mut
// return an empty list
TypeDefinitionList typeDefinitionList = session.getBinding().getRepositoryService().getTypeChildren(session.getRepositoryInfo().getId(), null, false, BigInteger.valueOf(100), BigInteger.valueOf(6), null);
if (typeDefinitionList == null) {
addResult(createResult(FAILURE, "getTypeChildren() returned nothing!"));
} else {
if (typeDefinitionList.getList() != null && !typeDefinitionList.getList().isEmpty()) {
addResult(createResult(FAILURE, "A getTypeChildren() call on the base types must retrun an empty list if skipCount is >= 6! The repository returned a list of " + typeDefinitionList.getList().size() + " elements."));
}
if (Boolean.TRUE.equals(typeDefinitionList.hasMoreItems())) {
addResult(createResult(FAILURE, "A getTypeChildren() call on the base types must retrun an empty list if skipCount is >= 6! The repository returned hasMoreItems == true."));
}
}
// test getTypeDescendants()
int numOfTypes = runTypeChecks(session, session.getTypeDescendants(null, -1, true));
addResult(createInfoResult("Checked " + numOfTypes + " type definitions."));
}
use of org.apache.chemistry.opencmis.commons.definitions.TypeDefinition in project structr by structr.
the class CMISRepositoryService method getTypeChildren.
private List<TypeDefinition> getTypeChildren(final String typeId, final Boolean includePropertyDefinitions) {
final Set<String> subtypes = new LinkedHashSet<>(SearchCommand.getAllSubtypesAsStringSet(typeId));
final ConfigurationProvider config = StructrApp.getConfiguration();
final List<TypeDefinition> result = new LinkedList<>();
// subtypes set from Structr contains initial type as well..
subtypes.remove(typeId);
for (final String subtype : subtypes) {
final Class subclass = config.getNodeEntityClass(subtype);
if (subclass != null) {
final TypeDefinition extendedTypeDefinition = extendTypeDefinition(subclass, includePropertyDefinitions);
if (extendedTypeDefinition != null) {
result.add(extendedTypeDefinition);
}
}
}
return result;
}
use of org.apache.chemistry.opencmis.commons.definitions.TypeDefinition in project structr by structr.
the class CMISRepositoryService method getBaseTypeChildren.
private List<TypeDefinition> getBaseTypeChildren(final BaseTypeId baseTypeId, final Boolean includePropertyDefinitions) {
final ConfigurationProvider config = StructrApp.getConfiguration();
final List<TypeDefinition> result = new LinkedList<>();
final App app = StructrApp.getInstance();
// static definition of base type children, add new types here!
switch(baseTypeId) {
case CMIS_DOCUMENT:
result.add(extendTypeDefinition(File.class, includePropertyDefinitions));
break;
case CMIS_FOLDER:
result.add(extendTypeDefinition(Folder.class, includePropertyDefinitions));
break;
case CMIS_ITEM:
try (final Tx tx = app.tx()) {
for (final SchemaNode schemaNode : app.nodeQuery(SchemaNode.class).sort(AbstractNode.name).getAsList()) {
final Class type = config.getNodeEntityClass(schemaNode.getClassName());
if (type != null) {
final CMISInfo info = getCMISInfo(type);
if (info != null && baseTypeId.equals(info.getBaseTypeId())) {
final TypeDefinition extendedTypeDefinition = extendTypeDefinition(type, includePropertyDefinitions);
if (extendedTypeDefinition != null) {
result.add(extendedTypeDefinition);
}
}
}
}
tx.success();
} catch (final FrameworkException fex) {
logger.warn("", fex);
}
break;
}
return result;
}
Aggregations