use of org.apache.chemistry.opencmis.commons.definitions.TypeDefinition in project structr by structr.
the class CMISRepositoryService method getTypeDescendants.
@Override
public List<TypeDefinitionContainer> getTypeDescendants(String repositoryId, String typeId, BigInteger depth, Boolean includePropertyDefinitions, ExtensionsData extension) {
// important: descendants are ALL children and children of children, i.e. the whole tree
/*
Id typeId: The typeId of an object-type specified in the repository.
- If specified, then the repository MUST return all of descendant types of the specified type.
- If not specified, then the Repository MUST return all types and MUST ignore the value of the depth parameter.
*/
final List<TypeDefinitionContainer> results = new LinkedList<>();
if (typeId != null) {
final BaseTypeId baseTypeId = getBaseTypeId(typeId);
if (baseTypeId != null) {
final TypeDefinition typeDefinition = getTypeDefinition(repositoryId, typeId, extension);
final TypeDefinitionContainer container = getTypeDefinitionContainer(typeDefinition, includePropertyDefinitions);
results.add(container);
} else {
final Class type = StructrApp.getConfiguration().getNodeEntityClass(typeId);
if (type != null) {
final TypeDefinition typeDefinition = extendTypeDefinition(type, includePropertyDefinitions);
if (typeDefinition != null) {
results.add(getTypeDefinitionContainer(typeDefinition, includePropertyDefinitions));
} else {
throw new CmisObjectNotFoundException("Type with ID " + typeId + " does not exist");
}
} else {
throw new CmisObjectNotFoundException("Type with ID " + typeId + " does not exist");
}
}
} else {
results.add(getTypeDefinitionContainer(getDocumentTypeDefinition(BaseTypeId.CMIS_DOCUMENT.value(), includePropertyDefinitions, true), includePropertyDefinitions));
results.add(getTypeDefinitionContainer(getFolderTypeDefinition(BaseTypeId.CMIS_FOLDER.value(), includePropertyDefinitions, true), includePropertyDefinitions));
results.add(getTypeDefinitionContainer(getItemTypeDefinition(BaseTypeId.CMIS_ITEM.value(), includePropertyDefinitions, true), includePropertyDefinitions));
results.add(getTypeDefinitionContainer(getPolicyTypeDefinition(BaseTypeId.CMIS_POLICY.value(), includePropertyDefinitions, true), includePropertyDefinitions));
results.add(getTypeDefinitionContainer(getRelationshipTypeDefinition(BaseTypeId.CMIS_RELATIONSHIP.value(), includePropertyDefinitions, true), includePropertyDefinitions));
results.add(getTypeDefinitionContainer(getSecondaryTypeDefinition(BaseTypeId.CMIS_SECONDARY.value(), includePropertyDefinitions, true), includePropertyDefinitions));
}
return results;
}
use of org.apache.chemistry.opencmis.commons.definitions.TypeDefinition in project copper-cms by PogeyanOSS.
the class RepositoryActor method createType.
private JSONObject createType(PostRequest request) throws IllegalArgumentException, CmisInvalidArgumentException, CmisRuntimeException {
String permission = request.getUserObject().getPermission();
if (!Helpers.checkingUserPremission(permission, "post")) {
throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
}
String typeStr = request.getParameter(QueryGetRequest.CONTROL_TYPE);
DateTimeFormat dateTimeFormat = request.getDateTimeFormatParameter();
if (typeStr == null) {
throw new CmisInvalidArgumentException("Type definition missing!");
}
// convert type definition
JSONParser parser = new JSONParser();
Object typeJson = null;
try {
typeJson = parser.parse(typeStr);
} catch (JSONParseException e) {
LOG.error("JSON Parser error: {}", ExceptionUtils.getStackTrace(e));
}
if (!(typeJson instanceof Map)) {
throw new CmisInvalidArgumentException("Invalid type definition!");
}
@SuppressWarnings("unchecked") TypeDefinition typeIn = JSONConverter.convertTypeDefinition((Map<String, Object>) typeJson);
TypeDefinition typeOut = CmisTypeServices.Impl.createType(request.getRepositoryId(), typeIn, null, request.getUserName());
JSONObject jsonType = JSONConverter.convert(typeOut, dateTimeFormat);
return jsonType;
}
use of org.apache.chemistry.opencmis.commons.definitions.TypeDefinition in project copper-cms by PogeyanOSS.
the class RepositoryActor method updateType.
private JSONObject updateType(PostRequest request) throws CmisInvalidArgumentException, IllegalArgumentException, CmisRuntimeException {
String permission = request.getUserObject().getPermission();
if (!Helpers.checkingUserPremission(permission, "post")) {
throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
}
String typeStr = request.getParameter(QueryGetRequest.CONTROL_TYPE);
DateTimeFormat dateTimeFormat = request.getDateTimeFormatParameter();
if (typeStr == null) {
throw new CmisInvalidArgumentException("Type definition missing!");
}
// convert type definition
JSONParser parser = new JSONParser();
Object typeJson = null;
try {
typeJson = parser.parse(typeStr);
} catch (JSONParseException e) {
LOG.error("JSON parse exception: {}", ExceptionUtils.getStackTrace(e));
}
if (!(typeJson instanceof Map)) {
throw new CmisInvalidArgumentException("Invalid type definition!");
}
@SuppressWarnings("unchecked") TypeDefinition typeIn = JSONConverter.convertTypeDefinition((Map<String, Object>) typeJson);
TypeDefinition typeOut = CmisTypeServices.Impl.updateType(request.getRepositoryId(), typeIn, null);
JSONObject jsonType = JSONConverter.convert(typeOut, dateTimeFormat);
return jsonType;
}
use of org.apache.chemistry.opencmis.commons.definitions.TypeDefinition in project copper-cms by PogeyanOSS.
the class BaseTypesTest method runTypeChecks.
private int runTypeChecks(Session session, List<Tree<ObjectType>> types) {
if (types == null) {
return 0;
}
int numOfTypes = 0;
CmisTestResult failure;
for (Tree<ObjectType> tree : types) {
failure = createResult(FAILURE, "Types tree contains null leaf!");
addResult(assertNotNull(tree, null, failure));
if (tree != null) {
numOfTypes++;
addResult(checkTypeDefinition(session, tree.getItem(), "Type spec compliance: " + tree.getItem().getId()));
// clear the cache to ensure that the type definition is
// reloaded from the repository
session.clear();
try {
TypeDefinition reloadedType = session.getTypeDefinition(tree.getItem().getId());
addResult(checkTypeDefinition(session, reloadedType, "Type spec compliance: " + (reloadedType == null ? "?" : reloadedType.getId())));
failure = createResult(FAILURE, "Type fetched via getTypeDescendants() is does not macth type fetched via getTypeDefinition(): " + tree.getItem().getId());
addResult(assertEquals(tree.getItem(), reloadedType, null, failure));
} catch (CmisObjectNotFoundException e) {
addResult(createResult(FAILURE, "Type fetched via getTypeDescendants() is not available via getTypeDefinition(): " + tree.getItem().getId(), e, false));
}
// clear the cache again to ensure that the type definition
// children are reloaded from the repository
session.clear();
try {
ItemIterable<ObjectType> reloadedTypeChildren = session.getTypeChildren(tree.getItem().getId(), true);
// check type children
Map<String, ObjectType> typeChilden = new HashMap<String, ObjectType>();
for (ObjectType childType : reloadedTypeChildren) {
if (childType == null) {
addResult(createResult(FAILURE, "The list of types contains a null entry!"));
continue;
}
addResult(checkTypeDefinition(session, childType, "Type spec compliance: " + childType.getId()));
typeChilden.put(childType.getId(), childType);
}
// compare type children and type descendants
if (tree.getChildren() == null) {
failure = createResult(FAILURE, "Type children fetched via getTypeDescendants() don't match type children fetched via getTypeChildren(): " + tree.getItem().getId());
addResult(assertEquals(0, typeChilden.size(), null, failure));
} else {
// collect the children
Map<String, ObjectType> typeDescendants = new HashMap<String, ObjectType>();
for (Tree<ObjectType> childType : tree.getChildren()) {
if ((childType != null) && (childType.getItem() != null)) {
typeDescendants.put(childType.getItem().getId(), childType.getItem());
}
}
failure = createResult(FAILURE, "Type children fetched via getTypeDescendants() don't match type children fetched via getTypeChildren(): " + tree.getItem().getId());
addResult(assertEquals(typeDescendants.size(), typeChilden.size(), null, failure));
for (ObjectType compareType : typeDescendants.values()) {
failure = createResult(FAILURE, "Type fetched via getTypeDescendants() doesn't match type fetched via getTypeChildren(): " + tree.getItem().getId());
addResult(assertEquals(compareType, typeChilden.get(compareType.getId()), null, failure));
}
}
} catch (CmisObjectNotFoundException e) {
addResult(createResult(FAILURE, "Type children fetched via getTypeDescendants() are not available via getTypeChildren(): " + tree.getItem().getId(), e, false));
}
numOfTypes += runTypeChecks(session, tree.getChildren());
}
}
return numOfTypes;
}
use of org.apache.chemistry.opencmis.commons.definitions.TypeDefinition in project copper-cms by PogeyanOSS.
the class CreateBigDocument method run.
@Override
public void run(Session session) {
CmisTestResult f;
// create a test folder
Folder testFolder = createTestFolder(session);
try {
String name = "bigdoc";
String objectTypeId = getDocumentTestTypeId();
String mimetype = "application/octet-stream";
// 10 MiB
final long size = 10 * 1024 * 1024;
InputStream in = new InputStream() {
private int counter = -1;
@Override
public int read() throws IOException {
counter++;
if (counter >= size) {
return -1;
}
return '0' + (counter / 10);
}
};
// create stream and properties
ContentStream contentStream = session.getObjectFactory().createContentStream(name, size, mimetype, in);
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, name);
properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
// check type
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;
VersioningState versioningState = (Boolean.TRUE.equals(docType.isVersionable()) ? VersioningState.MAJOR : VersioningState.NONE);
// create and fetch the document
ObjectId id = session.createDocument(properties, testFolder, contentStream, 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 size
f = createResult(FAILURE, "Content stream length doesn't match the uploaded content!", true);
assertEquals(size, doc.getContentStreamLength(), null, f);
// delete it
// doc.delete(true);
} finally {
// delete the test folder
// deleteTestFolder();
}
}
Aggregations