コード例 #1
0
ファイル: CMISHelper.java プロジェクト: JSantosP/camel
 public static Map<String, Object> propertyDataToMap(List<? extends PropertyData<?>> properties) {
   Map<String, Object> result = new HashMap<String, Object>();
   for (PropertyData<?> propertyData : properties) {
     result.put(propertyData.getId(), propertyData.getFirstValue());
   }
   return result;
 }
コード例 #2
0
  private <T> void constraintChoices(
      PropertyDefinition<T> definition, PropertyData<T> propertyData, String objectId) {
    // Check OpenChoice
    boolean openChoice = (definition.isOpenChoice() == null) ? true : false;
    if (openChoice) return;

    List<T> data = propertyData.getValues();
    // null or blank String value should be permitted within any choice list
    if (CollectionUtils.isEmpty(data)) return;

    List<Choice<T>> choices = definition.getChoices();
    if (CollectionUtils.isEmpty(choices) || CollectionUtils.isEmpty(data)) return;

    boolean included = false;
    if (definition.getCardinality() == Cardinality.SINGLE) {
      T d = data.get(0);

      if (d instanceof String && StringUtils.isBlank((String) d) || d == null) {
        return;
      } else {
        for (Choice<T> choice : choices) {
          List<T> value = choice.getValue();
          T v = value.get(0);
          if (v.equals(d)) {
            included = true;
            break;
          }
        }
      }

    } else if (definition.getCardinality() == Cardinality.MULTI) {
      List<T> values = new ArrayList<T>();
      for (Choice<T> choice : choices) {
        values.addAll(choice.getValue());
      }

      for (T d : data) {
        if (values.contains(d)) {
          included = true;
        } else {
          if (d instanceof String && StringUtils.isBlank((String) d) || d == null) {
            included = true;
          } else {
            included = false;
            break;
          }
        }
      }
    }

    if (!included) {
      constraint(objectId, propertyData.getId() + " property value must be one of choices");
    }
  }
コード例 #3
0
  @Override
  public <T> void constraintPropertyValue(
      String repositoryId, TypeDefinition typeDefinition, Properties properties, String objectId) {
    Map<String, PropertyDefinition<?>> propertyDefinitions =
        typeDefinition.getPropertyDefinitions();

    // Adding secondary types and its properties MAY be done in the same
    // operation
    List<String> secIds =
        DataUtil.getIdListProperty(properties, PropertyIds.SECONDARY_OBJECT_TYPE_IDS);
    if (CollectionUtils.isNotEmpty(secIds)) {
      for (String secId : secIds) {
        TypeDefinition sec = typeManager.getTypeById(repositoryId, secId).getTypeDefinition();
        for (Entry<String, PropertyDefinition<?>> entry : sec.getPropertyDefinitions().entrySet()) {
          if (!propertyDefinitions.containsKey(entry.getKey())) {
            propertyDefinitions.put(entry.getKey(), entry.getValue());
          }
        }
      }
    }

    for (PropertyData<?> _pd : properties.getPropertyList()) {
      PropertyData<T> pd = (PropertyData<T>) _pd;
      PropertyDefinition<T> propertyDefinition =
          (PropertyDefinition<T>) propertyDefinitions.get(pd.getId());
      // If an input property is not defined one, output error.
      if (propertyDefinition == null) constraint(objectId, "An undefined property is provided!");

      // Check "required" flag
      if (propertyDefinition.isRequired() && !DataUtil.valueExist(pd.getValues()))
        constraint(objectId, "An required property is not provided!");

      // Check choices
      constraintChoices(propertyDefinition, pd, objectId);

      // Check min/max length
      switch (propertyDefinition.getPropertyType()) {
        case STRING:
          constraintStringPropertyValue(propertyDefinition, pd, objectId);
          break;
        case DECIMAL:
          constraintDecimalPropertyValue(propertyDefinition, pd, objectId);
        case INTEGER:
          constraintIntegerPropertyValue(propertyDefinition, pd, objectId);
          break;
        default:
          break;
      }
    }
  }
コード例 #4
0
  @Override
  public void updateObject(
      StoredObject so, Map<String, PropertyData<?>> newProperties, String user) {
    // nothing to do
    Map<String, PropertyData<?>> properties = so.getProperties();
    for (String key : newProperties.keySet()) {
      PropertyData<?> value = newProperties.get(key);

      if (key.equals(PropertyIds.SECONDARY_OBJECT_TYPE_IDS)) {
        properties.put(key, value); // preserve it even if it is empty!
      } else if (null == value || value.getValues() == null || value.getFirstValue() == null) {
        // delete property
        properties.remove(key);
      } else {
        properties.put(key, value);
      }
    }
    // update system properties and secondary object type ids
    so.updateSystemBasePropertiesWhenModified(properties, user);
    properties.remove(PropertyIds.SECONDARY_OBJECT_TYPE_IDS);
  }
コード例 #5
0
  @Override
  public void invalidArgumentSecondaryTypeIds(String repositoryId, Properties properties) {
    if (properties == null) return;
    Map<String, PropertyData<?>> map = properties.getProperties();
    if (MapUtils.isEmpty(map)) return;

    List<String> results = new ArrayList<String>();
    PropertyData<?> ids = map.get(PropertyIds.SECONDARY_OBJECT_TYPE_IDS);
    if (ids == null || CollectionUtils.isEmpty(ids.getValues())) return;
    for (Object _id : ids.getValues()) {
      String id = (String) _id;
      TypeDefinitionContainer tdc = typeManager.getTypeById(repositoryId, id);
      if (tdc == null) {
        results.add(id);
      }
    }

    if (CollectionUtils.isNotEmpty(results)) {
      String msg =
          "Invalid cmis:SecondaryObjectTypeIds are provided:" + StringUtils.join(results, ",");
      invalidArgument(msg);
    }
  }
コード例 #6
0
  private static void testReturnedProperties(Map<String, PropertyData<?>> props) {
    for (PropertyData<?> pd : props.values()) {
      log.info("return property id: " + pd.getId() + ", value: " + pd.getValues());
    }

    PropertyData<?> pd = props.get(PropertyIds.NAME);
    assertNotNull(pd);
    assertEquals(PROP_NAME, pd.getFirstValue());
    pd = props.get(PropertyIds.OBJECT_TYPE_ID);
    assertEquals(VersionTestTypeSystemCreator.VERSION_TEST_DOCUMENT_TYPE_ID, pd.getFirstValue());
    pd = props.get(VersionTestTypeSystemCreator.PROPERTY_ID);
    assertEquals(PROP_VALUE, pd.getFirstValue());
  }
コード例 #7
0
  private void constraintIntegerPropertyValue(
      PropertyDefinition<?> definition, PropertyData<?> propertyData, String objectId) {
    final String msg = "AN INTEGER property violates the range constraints";
    BigInteger val = BigInteger.valueOf((Long) propertyData.getFirstValue());

    BigInteger min = ((PropertyIntegerDefinition) definition).getMinValue();
    if (min != null && min.compareTo(val) > 0) {
      constraint(objectId, msg);
    }

    BigInteger max = ((PropertyIntegerDefinition) definition).getMinValue();
    if (max != null && max.compareTo(val) < 0) {
      constraint(objectId, msg);
    }
  }
コード例 #8
0
  private void checkVersionProperties(
      String docId,
      VersioningState versioningState,
      Map<String, PropertyData<?>> props,
      String checkinComment) {
    for (PropertyData<?> pd : props.values()) {
      log.info("return property id: " + pd.getId() + ", value: " + pd.getValues());
    }

    DocumentTypeDefinition typeDef =
        (DocumentTypeDefinition)
            fRepSvc.getTypeDefinition(
                fRepositoryId, VersionTestTypeSystemCreator.VERSION_TEST_DOCUMENT_TYPE_ID, null);
    PropertyBoolean pdb = (PropertyBoolean) props.get(PropertyIds.IS_LATEST_VERSION);
    assertNotNull(pdb);
    boolean bVal = pdb.getFirstValue();
    assertTrue(bVal);

    pdb = (PropertyBoolean) props.get(PropertyIds.IS_MAJOR_VERSION);
    assertNotNull(pdb);
    bVal = pdb.getFirstValue();
    assertEquals(versioningState == VersioningState.MAJOR, bVal);

    pdb = (PropertyBoolean) props.get(PropertyIds.IS_LATEST_MAJOR_VERSION);
    assertNotNull(pdb);
    bVal = pdb.getFirstValue();
    assertEquals(versioningState == VersioningState.MAJOR, bVal);

    PropertyId pdid = (PropertyId) props.get(PropertyIds.VERSION_SERIES_ID);
    assertNotNull(pdid);
    String sVal = pdid.getFirstValue();
    //        if (typeDef.isVersionable())  // need not be
    //            assertFalse(docId.equals(sVal));
    //        else
    //            assertEquals(docId, sVal);

    pdb = (PropertyBoolean) props.get(PropertyIds.IS_VERSION_SERIES_CHECKED_OUT);
    assertNotNull(pdb);
    bVal = pdb.getFirstValue();
    assertEquals(versioningState == VersioningState.CHECKEDOUT, bVal);

    PropertyString pds = (PropertyString) props.get(PropertyIds.VERSION_SERIES_CHECKED_OUT_BY);
    assertNotNull(pds);
    sVal = pds.getFirstValue();
    if (versioningState == VersioningState.CHECKEDOUT) {
      assertTrue(sVal != null && sVal.length() > 0);
    } else {
      assertTrue(null == sVal || sVal.equals(""));
    }

    pdid = (PropertyId) props.get(PropertyIds.VERSION_SERIES_CHECKED_OUT_ID);
    assertNotNull(pdid);
    sVal = pdid.getFirstValue();
    if (versioningState == VersioningState.CHECKEDOUT) {
      assertTrue(sVal != null && sVal.length() > 0);
    } else {
      assertTrue(null == sVal || sVal.equals(""));
    }

    pds = (PropertyString) props.get(PropertyIds.CHECKIN_COMMENT);
    assertNotNull(pdb);
    sVal = pds.getFirstValue();
    if (checkinComment == null) {
      assertTrue(null == sVal);
    } else {
      assertEquals(checkinComment, sVal);
    }
  }
コード例 #9
0
ファイル: JcrFolder.java プロジェクト: OpenDataSpace/opencmis
  public static void setProperties(Node node, TypeDefinition type, Properties properties) {
    if (properties == null || properties.getProperties() == null) {
      throw new CmisConstraintException("No properties!");
    }

    Set<String> addedProps = new HashSet<String>();

    try {
      // check if all required properties are there
      for (PropertyData<?> prop : properties.getProperties().values()) {
        PropertyDefinition<?> propDef = type.getPropertyDefinitions().get(prop.getId());

        // do we know that property?
        if (propDef == null) {
          throw new CmisConstraintException("Property '" + prop.getId() + "' is unknown!");
        }

        // skip type id
        if (propDef.getId().equals(PropertyIds.OBJECT_TYPE_ID)) {
          log.warn("Cannot set " + PropertyIds.OBJECT_TYPE_ID + ". Ignoring");
          addedProps.add(prop.getId());
          continue;
        }

        // skip content stream file name
        if (propDef.getId().equals(PropertyIds.CONTENT_STREAM_FILE_NAME)) {
          log.warn("Cannot set " + PropertyIds.CONTENT_STREAM_FILE_NAME + ". Ignoring");
          addedProps.add(prop.getId());
          continue;
        }

        // can it be set?
        if (propDef.getUpdatability() == Updatability.READONLY) {
          throw new CmisConstraintException("Property '" + prop.getId() + "' is readonly!");
        }

        // empty properties are invalid
        if (PropertyHelper.isPropertyEmpty(prop)) {
          throw new CmisConstraintException("Property '" + prop.getId() + "' must not be empty!");
        }

        // add it
        JcrConverter.setProperty(node, prop);
        addedProps.add(prop.getId());
      }

      // check if required properties are missing and try to add default values if defined
      for (PropertyDefinition<?> propDef : type.getPropertyDefinitions().values()) {
        if (!addedProps.contains(propDef.getId())
            && propDef.getUpdatability() != Updatability.READONLY) {
          PropertyData<?> prop = PropertyHelper.getDefaultValue(propDef);
          if (prop == null && propDef.isRequired()) {
            throw new CmisConstraintException("Property '" + propDef.getId() + "' is required!");
          } else if (prop != null) {
            JcrConverter.setProperty(node, prop);
          }
        }
      }
    } catch (RepositoryException e) {
      log.debug(e.getMessage(), e);
      throw new CmisStorageException(e.getMessage(), e);
    }
  }