public static TypeDefinition convertTypeDefinition(final Map<String, Object> json) {
if (json == null) {
return null;
}
AbstractTypeDefinition result = null;
String id = getString(json, JSON_TYPE_ID);
// find base type
BaseTypeId baseType = getEnum(json, JSON_TYPE_BASE_ID, BaseTypeId.class);
if (baseType == null) {
throw new CmisInvalidArgumentException("Invalid base type: " + id);
}
switch (baseType) {
case CMIS_FOLDER:
result = new FolderTypeDefinitionImpl();
break;
case CMIS_DOCUMENT:
result = new DocumentTypeDefinitionImpl();
((DocumentTypeDefinitionImpl) result).setContentStreamAllowed(getEnum(json,
JSON_TYPE_CONTENTSTREAM_ALLOWED, ContentStreamAllowed.class));
((DocumentTypeDefinitionImpl) result).setIsVersionable(getBoolean(json, JSON_TYPE_VERSIONABLE));
break;
case CMIS_RELATIONSHIP:
result = new RelationshipTypeDefinitionImpl();
Object allowedSourceTypes = json.get(JSON_TYPE_ALLOWED_SOURCE_TYPES);
if (allowedSourceTypes instanceof List) {
List<String> types = new ArrayList<String>();
for (Object type : (List<Object>) allowedSourceTypes) {
if (type != null) {
types.add(type.toString());
}
}
((RelationshipTypeDefinitionImpl) result).setAllowedSourceTypes(types);
}
Object allowedTargetTypes = json.get(JSON_TYPE_ALLOWED_TARGET_TYPES);
if (allowedTargetTypes instanceof List) {
List<String> types = new ArrayList<String>();
for (Object type : (List<Object>) allowedTargetTypes) {
if (type != null) {
types.add(type.toString());
}
}
((RelationshipTypeDefinitionImpl) result).setAllowedTargetTypes(types);
}
break;
case CMIS_POLICY:
result = new PolicyTypeDefinitionImpl();
break;
case CMIS_ITEM:
result = new ItemTypeDefinitionImpl();
break;
case CMIS_SECONDARY:
result = new SecondaryTypeDefinitionImpl();
break;
default:
throw new CmisRuntimeException("Type '" + id + "' does not match a base type!");
}
result.setBaseTypeId(baseType);
result.setDescription(getString(json, JSON_TYPE_DESCRIPTION));
result.setDisplayName(getString(json, JSON_TYPE_DISPLAYNAME));
result.setId(id);
result.setIsControllableAcl(getBoolean(json, JSON_TYPE_CONTROLABLE_ACL));
result.setIsControllablePolicy(getBoolean(json, JSON_TYPE_CONTROLABLE_POLICY));
result.setIsCreatable(getBoolean(json, JSON_TYPE_CREATABLE));
result.setIsFileable(getBoolean(json, JSON_TYPE_FILEABLE));
result.setIsFulltextIndexed(getBoolean(json, JSON_TYPE_FULLTEXT_INDEXED));
result.setIsIncludedInSupertypeQuery(getBoolean(json, JSON_TYPE_INCLUDE_IN_SUPERTYPE_QUERY));
result.setIsQueryable(getBoolean(json, JSON_TYPE_QUERYABLE));
result.setLocalName(getString(json, JSON_TYPE_LOCALNAME));
result.setLocalNamespace(getString(json, JSON_TYPE_LOCALNAMESPACE));
result.setParentTypeId(getString(json, JSON_TYPE_PARENT_ID));
result.setQueryName(getString(json, JSON_TYPE_QUERYNAME));
Map<String, Object> typeMutabilityJson = getMap(json.get(JSON_TYPE_TYPE_MUTABILITY));
if (typeMutabilityJson != null) {
TypeMutabilityImpl typeMutability = new TypeMutabilityImpl();
typeMutability.setCanCreate(getBoolean(typeMutabilityJson, JSON_TYPE_TYPE_MUTABILITY_CREATE));
typeMutability.setCanUpdate(getBoolean(typeMutabilityJson, JSON_TYPE_TYPE_MUTABILITY_UPDATE));
typeMutability.setCanDelete(getBoolean(typeMutabilityJson, JSON_TYPE_TYPE_MUTABILITY_DELETE));
convertExtension(typeMutabilityJson, typeMutability, JSON_TYPE_TYPE_MUTABILITY_KEYS);
result.setTypeMutability(typeMutability);
}
Map<String, Object> propertyDefinitions = getMap(json.get(JSON_TYPE_PROPERTY_DEFINITIONS));
if (propertyDefinitions != null) {
for (Object propDef : propertyDefinitions.values()) {
result.addPropertyDefinition(convertPropertyDefinition(getMap(propDef)));
}
}
// handle extensions
convertExtension(json, result, TYPE_KEYS);