use of org.alfresco.opencmis.dictionary.PropertyDefinitionWrapper in project alfresco-repository by Alfresco.
the class CMISConnector method getNodeProperties.
public Properties getNodeProperties(CMISNodeInfo info, String filter) {
PropertiesImpl result = new PropertiesImpl();
Set<String> filterSet = splitFilter(filter);
for (PropertyDefinitionWrapper propDef : info.getType().getProperties()) {
if (!propDef.getPropertyId().equals(PropertyIds.OBJECT_ID)) {
// don't filter the object id
if ((filterSet != null) && (!filterSet.contains(propDef.getPropertyDefinition().getQueryName()))) {
// skip properties that are not in the filter
continue;
}
}
Serializable value = propDef.getPropertyAccessor().getValue(info);
result.addProperty(getProperty(propDef.getPropertyDefinition().getPropertyType(), propDef, value));
}
addAspectProperties(info, filter, result);
return result;
}
use of org.alfresco.opencmis.dictionary.PropertyDefinitionWrapper in project alfresco-repository by Alfresco.
the class CMISConnector method setAspectProperties.
private void setAspectProperties(NodeRef nodeRef, boolean isNameChanging, CmisExtensionElement aspectExtension) {
if (aspectExtension.getChildren() == null) {
return;
}
List<String> aspectsToAdd = new ArrayList<String>();
List<String> aspectsToRemove = new ArrayList<String>();
Map<QName, List<Serializable>> aspectProperties = new HashMap<QName, List<Serializable>>();
for (CmisExtensionElement extension : aspectExtension.getChildren()) {
if (!ALFRESCO_EXTENSION_NAMESPACE.equals(extension.getNamespace())) {
continue;
}
if (ASPECTS_TO_ADD.equals(extension.getName()) && (extension.getValue() != null)) {
aspectsToAdd.add(extension.getValue());
} else if (ASPECTS_TO_REMOVE.equals(extension.getName()) && (extension.getValue() != null)) {
aspectsToRemove.add(extension.getValue());
} else if (PROPERTIES.equals(extension.getName()) && (extension.getChildren() != null)) {
for (CmisExtensionElement property : extension.getChildren()) {
if (!property.getName().startsWith("property")) {
continue;
}
String propertyId = (property.getAttributes() == null ? null : property.getAttributes().get("propertyDefinitionId"));
if ((propertyId == null) || (property.getChildren() == null)) {
continue;
}
PropertyType propertyType = PropertyType.STRING;
DatatypeFactory df = null;
if (property.getName().equals("propertyBoolean")) {
propertyType = PropertyType.BOOLEAN;
} else if (property.getName().equals("propertyInteger")) {
propertyType = PropertyType.INTEGER;
} else if (property.getName().equals("propertyDateTime")) {
propertyType = PropertyType.DATETIME;
try {
df = DatatypeFactory.newInstance();
} catch (DatatypeConfigurationException e) {
throw new CmisRuntimeException("Aspect conversation exception: " + e.getMessage(), e);
}
} else if (property.getName().equals("propertyDecimal")) {
propertyType = PropertyType.DECIMAL;
}
ArrayList<Serializable> values = new ArrayList<Serializable>();
if (property.getChildren() != null) {
// {
for (CmisExtensionElement valueElement : property.getChildren()) {
if ("value".equals(valueElement.getName())) {
switch(propertyType) {
case BOOLEAN:
try {
values.add(Boolean.parseBoolean(valueElement.getValue()));
} catch (Exception e) {
throw new CmisInvalidArgumentException("Invalid property aspect value: " + propertyId, e);
}
break;
case DATETIME:
try {
values.add(df.newXMLGregorianCalendar(valueElement.getValue()).toGregorianCalendar());
} catch (Exception e) {
throw new CmisInvalidArgumentException("Invalid property aspect value: " + propertyId, e);
}
break;
case INTEGER:
BigInteger value = null;
try {
value = new BigInteger(valueElement.getValue());
} catch (Exception e) {
throw new CmisInvalidArgumentException("Invalid property aspect value: " + propertyId, e);
}
// overflow check
PropertyDefinitionWrapper propDef = getOpenCMISDictionaryService().findProperty(propertyId);
if (propDef == null) {
throw new CmisInvalidArgumentException("Property " + propertyId + " is unknown!");
}
QName propertyQName = propDef.getPropertyAccessor().getMappedProperty();
if (propertyQName == null) {
throw new CmisConstraintException("Unable to set property " + propertyId + "!");
}
org.alfresco.service.cmr.dictionary.PropertyDefinition def = dictionaryService.getProperty(propertyQName);
QName dataDef = def.getDataType().getName();
if (dataDef.equals(DataTypeDefinition.INT) && (value.compareTo(maxInt) > 0 || value.compareTo(minInt) < 0)) {
throw new CmisConstraintException("Value is out of range for property " + propertyId);
}
if (dataDef.equals(DataTypeDefinition.LONG) && (value.compareTo(maxLong) > 0 || value.compareTo(minLong) < 0)) {
throw new CmisConstraintException("Value is out of range for property " + propertyId);
}
values.add(value);
break;
case DECIMAL:
try {
values.add(new BigDecimal(valueElement.getValue()));
} catch (Exception e) {
throw new CmisInvalidArgumentException("Invalid property aspect value: " + propertyId, e);
}
break;
default:
values.add(valueElement.getValue());
}
}
}
}
aspectProperties.put(QName.createQName(propertyId, namespaceService), values);
}
}
}
// remove and add aspects
String aspectType = null;
try {
for (String aspect : aspectsToRemove) {
aspectType = aspect;
TypeDefinitionWrapper type = getType(aspect);
if (type == null) {
throw new CmisInvalidArgumentException("Invalid aspect: " + aspectType);
}
QName typeName = type.getAlfrescoName();
// if aspect is hidden aspect, remove only if hidden node is not client controlled
if (typeName.equals(ContentModel.ASPECT_HIDDEN)) {
if (hiddenAspect.isClientControlled(nodeRef) || aspectProperties.containsKey(ContentModel.PROP_CLIENT_CONTROLLED)) {
// manipulate hidden aspect only if client controlled
nodeService.removeAspect(nodeRef, typeName);
}
// if(!isNameChanging && !hiddenAspect.isClientControlled(nodeRef) && !aspectProperties.containsKey(ContentModel.PROP_CLIENT_CONTROLLED))
// {
// nodeService.removeAspect(nodeRef, typeName);
// }
} else {
nodeService.removeAspect(nodeRef, typeName);
}
}
for (String aspect : aspectsToAdd) {
aspectType = aspect;
TypeDefinitionWrapper type = getType(aspect);
if (type == null) {
throw new CmisInvalidArgumentException("Invalid aspect: " + aspectType);
}
QName typeName = type.getAlfrescoName();
// if aspect is hidden aspect, remove only if hidden node is not client controlled
if (typeName.equals(ContentModel.ASPECT_HIDDEN)) {
if (hiddenAspect.isClientControlled(nodeRef) || aspectProperties.containsKey(ContentModel.PROP_CLIENT_CONTROLLED)) {
// manipulate hidden aspect only if client controlled
nodeService.addAspect(nodeRef, type.getAlfrescoName(), Collections.<QName, Serializable>emptyMap());
}
// if(!isNameChanging && !hiddenAspect.isClientControlled(nodeRef) && !aspectProperties.containsKey(ContentModel.PROP_CLIENT_CONTROLLED))
// {
// nodeService.addAspect(nodeRef, type.getAlfrescoName(),
// Collections.<QName, Serializable> emptyMap());
// }
} else {
nodeService.addAspect(nodeRef, type.getAlfrescoName(), Collections.<QName, Serializable>emptyMap());
}
}
} catch (InvalidAspectException e) {
throw new CmisInvalidArgumentException("Invalid aspect: " + aspectType);
} catch (InvalidNodeRefException e) {
throw new CmisInvalidArgumentException("Invalid node: " + nodeRef);
}
// set property
for (Map.Entry<QName, List<Serializable>> property : aspectProperties.entrySet()) {
QName propertyQName = property.getKey();
if (property.getValue().isEmpty()) {
if (HiddenAspect.HIDDEN_PROPERTIES.contains(property.getKey())) {
if (hiddenAspect.isClientControlled(nodeRef) || aspectProperties.containsKey(ContentModel.PROP_CLIENT_CONTROLLED)) {
// manipulate hidden aspect property only if client controlled
nodeService.removeProperty(nodeRef, propertyQName);
}
} else {
nodeService.removeProperty(nodeRef, property.getKey());
}
} else {
if (HiddenAspect.HIDDEN_PROPERTIES.contains(property.getKey())) {
if (hiddenAspect.isClientControlled(nodeRef) || aspectProperties.containsKey(ContentModel.PROP_CLIENT_CONTROLLED)) {
// manipulate hidden aspect property only if client controlled
nodeService.setProperty(nodeRef, property.getKey(), property.getValue().size() == 1 ? property.getValue().get(0) : (Serializable) property.getValue());
}
} else {
Serializable value = (Serializable) property.getValue();
nodeService.setProperty(nodeRef, property.getKey(), property.getValue().size() == 1 ? property.getValue().get(0) : value);
}
}
}
}
use of org.alfresco.opencmis.dictionary.PropertyDefinitionWrapper in project alfresco-repository by Alfresco.
the class CMISConnector method addAspectProperties.
private void addAspectProperties(CMISNodeInfo info, String filter, PropertiesImpl result) {
if (getRequestCmisVersion().equals(CmisVersion.CMIS_1_1)) {
Set<String> propertyIds = new HashSet<>();
Set<String> filterSet = splitFilter(filter);
Set<QName> aspects = info.getNodeAspects();
for (QName aspect : aspects) {
TypeDefinitionWrapper aspectType = getOpenCMISDictionaryService().findNodeType(aspect);
if (aspectType == null) {
continue;
}
for (PropertyDefinitionWrapper propDef : aspectType.getProperties()) {
if (propertyIds.contains(propDef.getPropertyId())) {
// skip properties that have already been added
continue;
}
if ((filterSet != null) && (!filterSet.contains(propDef.getPropertyDefinition().getQueryName()))) {
// skip properties that are not in the filter
continue;
}
Serializable value = propDef.getPropertyAccessor().getValue(info);
result.addProperty(getProperty(propDef.getPropertyDefinition().getPropertyType(), propDef, value));
// mark property as 'added'
propertyIds.add(propDef.getPropertyId());
}
}
}
}
use of org.alfresco.opencmis.dictionary.PropertyDefinitionWrapper in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method getCheckedOutDocs.
@Override
public ObjectList getCheckedOutDocs(String repositoryId, String folderId, String filter, String orderBy, Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter, BigInteger maxItems, BigInteger skipCount, ExtensionsData extension) {
long start = System.currentTimeMillis();
checkRepositoryId(repositoryId);
// convert BigIntegers to int
int max = (maxItems == null ? Integer.MAX_VALUE : maxItems.intValue());
int skip = (skipCount == null || skipCount.intValue() < 0 ? 0 : skipCount.intValue());
// prepare query
SearchParameters params = new SearchParameters();
params.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO);
if (folderId == null) {
params.setQuery("+=cm:workingCopyOwner:\"" + AuthenticationUtil.getFullyAuthenticatedUser() + "\"");
params.addStore(connector.getRootStoreRef());
} else {
CMISNodeInfo folderInfo = getOrCreateFolderInfo(folderId, "Folder");
params.setQuery("+=cm:workingCopyOwner:\"" + AuthenticationUtil.getFullyAuthenticatedUser() + "\" AND +=PARENT:\"" + folderInfo.getNodeRef().toString() + "\"");
params.addStore(folderInfo.getNodeRef().getStoreRef());
}
// set up order
if (orderBy != null) {
String[] parts = orderBy.split(",");
for (int i = 0; i < parts.length; i++) {
String[] sort = parts[i].split(" +");
if (sort.length < 1) {
continue;
}
PropertyDefinitionWrapper propDef = connector.getOpenCMISDictionaryService().findPropertyByQueryName(sort[0]);
if (propDef != null) {
if (propDef.getPropertyDefinition().isOrderable()) {
QName sortProp = propDef.getPropertyAccessor().getMappedProperty();
if (sortProp != null) {
boolean sortAsc = (sort.length == 1) || sort[1].equalsIgnoreCase("asc");
params.addSort(propDef.getPropertyLuceneBuilder().getLuceneFieldName(), sortAsc);
} else {
if (logger.isDebugEnabled()) {
logger.debug("Ignore sort property '" + sort[0] + " - mapping not found");
}
}
} else {
if (logger.isDebugEnabled()) {
logger.debug("Ignore sort property '" + sort[0] + " - not orderable");
}
}
} else {
if (logger.isDebugEnabled()) {
logger.debug("Ignore sort property '" + sort[0] + " - query name not found");
}
}
}
}
// execute query
ResultSet resultSet = null;
List<NodeRef> nodeRefs;
try {
resultSet = connector.getSearchService().query(params);
nodeRefs = resultSet.getNodeRefs();
} finally {
if (resultSet != null) {
resultSet.close();
}
}
// collect results
ObjectListImpl result = new ObjectListImpl();
List<ObjectData> list = new ArrayList<ObjectData>();
result.setObjects(list);
int skipCounter = skip;
if (max > 0) {
for (NodeRef nodeRef : nodeRefs) {
// TODO - perhaps filter by path in the query instead?
if (connector.filter(nodeRef)) {
continue;
}
if (skipCounter > 0) {
skipCounter--;
continue;
}
if (list.size() == max) {
break;
}
try {
// create a CMIS object
CMISNodeInfo ni = createNodeInfo(nodeRef);
ObjectData object = connector.createCMISObject(ni, filter, includeAllowableActions, includeRelationships, renditionFilter, false, false);
boolean isObjectInfoRequired = getContext().isObjectInfoRequired();
if (isObjectInfoRequired) {
getObjectInfo(repositoryId, ni.getObjectId(), includeRelationships);
}
// add it
list.add(object);
} catch (InvalidNodeRefException e) {
// ignore invalid objects
} catch (CmisObjectNotFoundException e) {
// ignore objects that have not been found (perhaps because their type is unknown to CMIS)
}
}
}
// has more ?
result.setHasMoreItems(nodeRefs.size() - skip > list.size());
logGetObjectsCall("getCheckedOutDocs", start, folderId, list.size(), filter, includeAllowableActions, includeRelationships, renditionFilter, null, extension, skipCount, maxItems, orderBy, null);
return result;
}
use of org.alfresco.opencmis.dictionary.PropertyDefinitionWrapper in project alfresco-repository by Alfresco.
the class CMISTest method testACE3322.
/**
* ACE-3322
*/
@Test
public void testACE3322() {
final String[] types = { "cmis:document", "cmis:relationship", "cmis:folder", "cmis:item" };
CmisServiceCallback<String> callback = new CmisServiceCallback<String>() {
@Override
public String execute(CmisService cmisService) {
for (int i = 0; i < types.length; i++) {
List<TypeDefinitionWrapper> baseTypes = cmisDictionaryService.getBaseTypes();
assertNotNull(baseTypes);
checkDefs(baseTypes);
List<TypeDefinitionWrapper> children = cmisDictionaryService.getChildren(types[i]);
assertNotNull(children);
// Check that children were updated
checkDefs(children);
}
return "";
}
private void checkDefs(List<TypeDefinitionWrapper> defs) {
for (TypeDefinitionWrapper def : defs) {
assertNotNull("Type definition was not updated. Please refer to ACE-3322", def.getTypeDefinition(false).getDisplayName());
assertNotNull("Type definition was not updated. Please refer to ACE-3322", def.getTypeDefinition(false).getDescription());
// Check that property's display name and description were updated
for (PropertyDefinitionWrapper property : def.getProperties()) {
assertNotNull("Display name is null", property.getPropertyDefinition().getDisplayName());
assertNotNull("Description is null", property.getPropertyDefinition().getDescription());
}
}
}
};
withCmisService(callback, CmisVersion.CMIS_1_1);
}
Aggregations