/** * Extracts the resource type from a set of CMIS properties.<p> * * @param properties the CMIS properties * @param defaultValue the default value * * @return the resource type property, or the default value if the property was not found */ protected String getResourceTypeFromProperties(Map<String, PropertyData<?>> properties, String defaultValue) { PropertyData<?> typeProp = properties.get(CmsCmisTypeManager.PROPERTY_RESOURCE_TYPE); String resTypeName = defaultValue; if (typeProp != null) { resTypeName = (String)typeProp.getFirstValue(); } return resTypeName; }
@Override public <T> T getPropertyValueById(String id) { PropertyData<T> property = getPropertyById(id); if (property == null) { return null; } return property.getFirstValue(); }
@Override public <T> T getPropertyValueByQueryName(String queryName) { PropertyData<T> property = getPropertyByQueryName(queryName); if (property == null) { return null; } return property.getFirstValue(); }
@Override public <T> T getPropertyValueById(String id) { PropertyData<T> property = getPropertyById(id); if (property == null) { return null; } return property.getFirstValue(); }
@Override public <T> T getPropertyValueByQueryName(String queryName) { PropertyData<T> property = getPropertyByQueryName(queryName); if (property == null) { return null; } return property.getFirstValue(); }
/** * Open CMIS returns dates as a Calendar but freemarker cannot * cope with these so convert them to a Date. * @param result Queryresult from CMIS * @param propertyId property name * @return Date */ public static Date getDateProperty(QueryResult result, String propertyId) { PropertyData<Object> property = result.getPropertyById(propertyId); if (property == null) return null; Calendar calendar = (Calendar)property.getFirstValue(); return calendar != null ? calendar.getTime() : null; } }
/** * Helper method to create OpenCms property objects from a map of CMIS properties.<p> * * @param properties the CMIS properties * * @return the OpenCms properties */ protected List<CmsProperty> getOpenCmsProperties(Map<String, PropertyData<?>> properties) { List<CmsProperty> cmsProperties = new ArrayList<CmsProperty>(); for (Map.Entry<String, PropertyData<?>> entry : properties.entrySet()) { String propId = entry.getKey(); if (propId.startsWith(CmsCmisTypeManager.PROPERTY_PREFIX)) { String propName = propId.substring(CmsCmisTypeManager.PROPERTY_PREFIX.length()); String value = (String)entry.getValue().getFirstValue(); if (value == null) { value = ""; } cmsProperties.add(new CmsProperty(propName, value, null)); } } return cmsProperties; }
/** * Returns the first value of a property or <code>null</code> if the * property is not set. */ private Object getFirstValue(String id) { if (properties == null || properties.getProperties() == null) { return null; } PropertyData<?> property = properties.getProperties().get(id); if (property == null) { return null; } return property.getFirstValue(); }
/** * Returns the first value of a property or <code>null</code> if the * property is not set. */ private Object getFirstValue(String id) { if (properties == null || properties.getProperties() == null) { return null; } PropertyData<?> property = properties.getProperties().get(id); if (property == null) { return null; } return property.getFirstValue(); }
@Override public void validate(PropertyDefinition<String> propDef, PropertyData<String> property) { super.validate(propDef, property); long maxLen = ((PropertyStringDefinition) propDef).getMaxLength() == null ? -1 : ((PropertyStringDefinition) propDef).getMaxLength().longValue(); long len = property.getFirstValue() == null ? -1 : property.getFirstValue().length(); // check max length if (maxLen >= 0 && len >= 0 && maxLen < len) { throw new CmisConstraintException("For property with id " + propDef.getId() + " the length of " + len + " is bigger than the maximum allowed length " + maxLen); } } }
@Override public Map<String, Date> getModifiedTimesOfAssets(Collection<String> assetIds) { Map<String, Date> map = new TreeMap<String, Date>(); String idList = buildIdList(assetIds); String cmisQuery = MessageFormat.format(modifiedTimesByAssetIds, idList); ItemIterable<QueryResult> results = runQuery(cmisQuery); Iterator<QueryResult> iterator = results.iterator(); Date modifiedTime; String id; while (iterator.hasNext()) { QueryResult result = iterator.next(); modifiedTime = SqlUtils.getDateProperty(result, Resource.PROPERTY_MODIFIED_TIME); id = (String) result.getPropertyById(PropertyIds.OBJECT_ID).getFirstValue(); map.put(id, modifiedTime); } return map; }
public void doQuery(String cql, int maxItems) { Session cmisSession = getCmisSession(); OperationContext oc = new OperationContextImpl(); oc.setMaxItemsPerPage(maxItems); ItemIterable<QueryResult> results = cmisSession.query(cql, false, oc); for (QueryResult result : results) { for (PropertyData<?> prop : result.getProperties()) { System.out.println(prop.getQueryName() + ": " + prop.getFirstValue()); } System.out.println("--------------------------------------"); } System.out.println("--------------------------------------"); System.out.println("Total number: " + results.getTotalNumItems()); System.out.println("Has more: " + results.getHasMoreItems()); System.out.println("--------------------------------------"); }
/** * retrieve the index-th folder from given level of the hierarchy starting * at rootId * * @param rootId * @param level * @param index * @return */ public String getFolderId(String rootId, int level, int index) { String objectId = rootId; final String requiredProperties = PropertyIds.OBJECT_ID + "," + PropertyIds.OBJECT_TYPE_ID + "," + PropertyIds.BASE_TYPE_ID; // Note: This works because first folders are created then documents for (int i = 0; i < level; i++) { ObjectInFolderList result = fNavSvc.getChildren(fRepositoryId, objectId, requiredProperties, PropertyIds.OBJECT_TYPE_ID, false, IncludeRelationships.NONE, null, true, BigInteger.valueOf(-1), BigInteger.valueOf(-1), null); List<ObjectInFolderData> children = result.getObjects(); ObjectData child = children.get(index).getObject(); objectId = (String) child.getProperties().getProperties().get(PropertyIds.OBJECT_ID).getFirstValue(); } return objectId; }
/** * Throws an exception if the given property isn't set or of the wrong type. */ protected void checkProperty(Properties properties, String propertyId, Class<?> clazz) { if (properties.getProperties() == null) { throw new CmisInvalidArgumentException("Property " + propertyId + " must be set!"); } PropertyData<?> property = properties.getProperties().get(propertyId); if (property == null) { throw new CmisInvalidArgumentException("Property " + propertyId + " must be set!"); } Object value = property.getFirstValue(); if (value == null) { throw new CmisInvalidArgumentException("Property " + propertyId + " must have a value!"); } if (!clazz.isAssignableFrom(value.getClass())) { throw new CmisInvalidArgumentException("Property " + propertyId + " has the wrong type!"); } }
@Override public ObjectType getTypeFromObjectData(ObjectData objectData) { if (objectData == null || objectData.getProperties() == null || objectData.getProperties().getProperties() == null) { return null; } PropertyData<?> typeProperty = objectData.getProperties().getProperties().get(PropertyIds.OBJECT_TYPE_ID); if (!(typeProperty instanceof PropertyId)) { return null; } return this.session.getTypeDefinition((String) typeProperty.getFirstValue()); }
@Override public ObjectType getTypeFromObjectData(ObjectData objectData) { if (objectData == null || objectData.getProperties() == null || objectData.getProperties().getProperties() == null) { return null; } PropertyData<?> typeProperty = objectData.getProperties().getProperties().get(PropertyIds.OBJECT_TYPE_ID); if (!(typeProperty instanceof PropertyId)) { return null; } return this.session.getTypeDefinition((String) typeProperty.getFirstValue()); }
@Override public void validate(PropertyDefinition<BigDecimal> propDef, PropertyData<BigDecimal> property) { super.validate(propDef, property); BigDecimal propVal = property.getFirstValue(); BigDecimal minVal = ((PropertyDecimalDefinition) propDef).getMinValue(); BigDecimal maxVal = ((PropertyDecimalDefinition) propDef).getMaxValue(); // check min and max if (minVal != null && propVal != null && propVal.compareTo(minVal) == -1) { throw new CmisConstraintException("For property with id " + propDef.getId() + " the value " + propVal + " is less than the minimum value " + minVal); } if (maxVal != null && propVal != null && propVal.compareTo(maxVal) == 1) { throw new CmisConstraintException("For property with id " + propDef.getId() + " the value " + propVal + " is bigger than the maximum value " + maxVal); } } }
@Override public void validate(PropertyDefinition<BigInteger> propDef, PropertyData<BigInteger> property) { super.validate(propDef, property); BigInteger propVal = property.getFirstValue(); BigInteger minVal = ((PropertyIntegerDefinition) propDef).getMinValue(); BigInteger maxVal = ((PropertyIntegerDefinition) propDef).getMaxValue(); // check min and max if (minVal != null && propVal != null && propVal.compareTo(minVal) == -1) { throw new CmisConstraintException("For property with id " + propDef.getId() + " the value " + propVal + " is less than the minimum value " + minVal); } if (maxVal != null && propVal != null && propVal.compareTo(maxVal) == 1) { throw new CmisConstraintException("For property with id " + propDef.getId() + " the value " + propVal + " is bigger than the maximum value " + maxVal); } } }
@Override public List<Folder> getParents(OperationContext context) { if (isRootFolder()) { return Collections.emptyList(); } String objectId = getObjectId(); ObjectData bindingParent = getBinding().getNavigationService().getFolderParent(getRepositoryId(), objectId, getPropertyQueryName(PropertyIds.OBJECT_ID), null); if (bindingParent.getProperties() == null) { // should not happen... throw new CmisRuntimeException("Repository sent invalid data!"); } // get id property PropertyData<?> idProperty = bindingParent.getProperties().getProperties().get(PropertyIds.OBJECT_ID); if (!(idProperty instanceof PropertyId) && !(idProperty instanceof PropertyString)) { // the repository sent an object without a valid object id... throw new CmisRuntimeException("Repository sent invalid data! No object id!"); } // fetch the object and make sure it is a folder CmisObject parentFolder = getSession().getObject((String) idProperty.getFirstValue(), context); if (!(parentFolder instanceof Folder)) { // the repository sent an object that is not a folder... throw new CmisRuntimeException("Repository sent invalid data! Object is not a folder!"); } return Collections.singletonList((Folder) parentFolder); }
@Override public Void execute(CmisService cmisService) { // get original document ObjectData originalDoc = cmisService.getObject(testContext.getRepositoryId(), objectData.getId(), null, true, IncludeRelationships.NONE, null, false, true, null); Map<String, PropertyData<?>> properties = originalDoc.getProperties().getProperties(); PropertyData<Boolean> isVersionSeriesCheckedOutProp = (PropertyData<Boolean>)properties.get(PropertyIds.IS_VERSION_SERIES_CHECKED_OUT); assertNotNull(isVersionSeriesCheckedOutProp); Boolean isVersionSeriesCheckedOut = isVersionSeriesCheckedOutProp.getFirstValue(); assertNotNull(isVersionSeriesCheckedOut); assertEquals(Boolean.FALSE, isVersionSeriesCheckedOut); return null; } });