Package org.exoplatform.services.jcr.core.nodetype

Examples of org.exoplatform.services.jcr.core.nodetype.PropertyDefinitionData


               + "< 'constraint1', 'constraint2' queryops '=, <>, <, <=, >, >=, LIKE' nofulltext noqueryorder "
               + "+ ns:node (ns:reqType1, ns:reqType2) = ns:defaultType mandatory autocreated protected sns VERSION "
               + "+ ns:node2 (ns:reqType1, ns:reqType2, nt:subBase)  man p * VERSION";
         NodeTypeData ntdActual = parseString(ntString).get(0);

         PropertyDefinitionData ptdActual = ntdActual.getDeclaredPropertyDefinitions()[0];

         NodeDefinitionData chdActual1 = ntdActual.getDeclaredChildNodeDefinitions()[0];
         NodeDefinitionData chdActual2 = ntdActual.getDeclaredChildNodeDefinitions()[1];

         /** Correct names */
         assertEquals(ntdActual.getName(), toName("ns:NodeType"));
         /** Correct attributes */
         assertEquals(ntdActual.getPrimaryItemName(), toName("ex:property"));
         assertEquals(ntdActual.isMixin(), true);
         assertEquals(ntdActual.hasOrderableChildNodes(), true);
         //         assertEquals(ntdActual.isAbstract(), true);
         //         assertEquals(ntdActual.isQueryable(), false);
         /** Correct supertypes */
         assertTrue(Arrays.deepEquals(ntdActual.getDeclaredSupertypeNames(), new InternalQName[]{
            toName("ns:ParentType1"), toName("ns:ParentType2")}));

         /** Correct properties */
         assertEquals(ptdActual.getName(), toName("ex:property"));
         assertEquals(ptdActual.isAutoCreated(), true);
         assertEquals(ptdActual.isMandatory(), true);
         assertEquals(ptdActual.getOnParentVersion(), OnParentVersionAction.INITIALIZE);
         assertEquals(ptdActual.isProtected(), true);
         assertEquals(ptdActual.getRequiredType(), PropertyType.STRING);
         assertTrue(Arrays.deepEquals(ptdActual.getValueConstraints(), new String[]{"constraint1", "constraint2"}));
         assertTrue(Arrays.deepEquals(ptdActual.getDefaultValues(), new String[]{"default1", "default2"}));
         assertEquals(ptdActual.isMultiple(), true);
         //         assertEquals(ptdActual.isQueryOrderable(), false);
         //         String[] actual = ptdActual.getAvailableQueryOperators();
         //         String[] expected = new String[]{"=", "<>", "<", "<=", ">", ">=", "LIKE"};
         //         Arrays.sort(actual);
         //         Arrays.sort(expected);
View Full Code Here


      if (defs == null || defs.getAnyDefinition() == null)
      {
         throw new RepositoryException("Property definition '" + propertyName.getAsString() + "' is not found.");
      }

      PropertyDefinitionData def = defs.getDefinition(isMultiValue);
      if (def != null && def.isProtected())
      {
         throw new ConstraintViolationException("Can not set protected property "
            + locationFactory.createJCRPath(qpath).getAsString(false));
      }

      if (multiValue && (def == null || (prevProp != null && !prevProp.isMultiValued())))
      {
         throw new ValueFormatException("Can not assign multiple-values Value to a single-valued property "
            + locationFactory.createJCRPath(qpath).getAsString(false));
      }

      if (!multiValue && (def == null || (prevProp != null && prevProp.isMultiValued())))
      {
         throw new ValueFormatException("Can not assign single-value Value to a multiple-valued property "
            + locationFactory.createJCRPath(qpath).getAsString(false));
      }

      // Check if checked-in (versionable)
      if (!parentNode.checkedOut())
      {
         throw new VersionException("Node " + parentNode.getPath() + " or its nearest ancestor is checked-in");
      }

      // Check is locked
      if (!parentNode.checkLocking())
      {
         throw new LockException("Node " + parentNode.getPath() + " is locked ");
      }

      List<ValueData> valueDataList = new ArrayList<ValueData>();

      // cast to required type if neccessary
      int requiredType = def.getRequiredType();

      int propType = requiredType;
      // if list of values not null
      if (propertyValues != null)
      {
         // All Value objects in the array must be of the same type, otherwise a
         // ValueFormatException is thrown.
         if (propertyValues.length > 1)
         {
            if (propertyValues[0] != null)
            {
               int vType = propertyValues[0].getType();
               for (Value val : propertyValues)
               {
                  if (val != null && vType != val.getType())
                  {
                     throw new ValueFormatException("All Value objects in the array must be of the same type");
                  }
               }
            }
         }

         // if value count >0 and original type not UNDEFINED
         if (propertyValues.length > 0 && requiredType == PropertyType.UNDEFINED)
         {
            // if type what we expected to be UNDEFINED
            // set destination type = type of values else type expectedType
            if (expectedType == PropertyType.UNDEFINED)
            {
               for (Value val : propertyValues)
               {
                  if (val != null)
                  {
                     expectedType = val.getType();
                     break;
                  }
               }
            }
            propType = expectedType;
         }
         // fill datas and also remove null values and reorder values
         for (Value value : propertyValues)
         {
            if (value != null)
            {
               valueDataList.add(valueData(value, propType));
            }
            else
            {
               if (log.isDebugEnabled())
               {
                  log.debug("Set null value (" + getPath() + ", multivalued: " + multiValue + ")");
               }
            }
         }
      }

      // Check value constraints
      checkValueConstraints(def, valueDataList, propType);

      if (requiredType != PropertyType.UNDEFINED && expectedType != PropertyType.UNDEFINED
         && requiredType != expectedType)
      {
         throw new ConstraintViolationException(" the type parameter "
            + ExtendedPropertyType.nameFromValue(expectedType) + " and the "
            + "type of the property do not match required type" + ExtendedPropertyType.nameFromValue(requiredType));
      }

      PropertyImpl prop;
      if (state != ItemState.DELETED)
      {
         // add or update      
         TransientPropertyData newData =
            new TransientPropertyData(qpath, identifier, version, propType, parentNode.getInternalIdentifier(),
               multiValue, valueDataList);

         ItemState itemState = new ItemState(newData, state, true, qpath, false);
         prop = (PropertyImpl)dataManager.update(itemState, true);

         // launch event: post-set
         session.getActionHandler().postSetProperty(prevProperty, prop, state);
      }
      else
      {
         if (def.isMandatory())
         {
            throw new ConstraintViolationException("Can not remove (by setting null value) mandatory property "
               + locationFactory.createJCRPath(qpath).getAsString(false));
         }
View Full Code Here

         {
            newProperty = endUuid(nodeData, propName, propertiesMap.get(Constants.JCR_UUID));
         }
         else
         {
            PropertyDefinitionData pDef;
            PropertyDefinitionDatas defs;
            InternalQName[] nTypes = mixinNodeTypes.toArray(new InternalQName[mixinNodeTypes.size() + 1]);
            nTypes[nTypes.length - 1] = nodeData.getPrimaryTypeName();
            defs = nodeTypeDataManager.getPropertyDefinitions(propName, nTypes);
            if (defs == null || defs.getAnyDefinition() == null)
            {
               if (!((Boolean)context.get(ContentImporter.RESPECT_PROPERTY_DEFINITIONS_CONSTRAINTS)))
               {
                  log.warn("Property definition not found for " + propName.getAsString());
                  continue;
               }
               throw new RepositoryException("Property definition not found for " + propName.getAsString());
            }

            pDef = defs.getAnyDefinition();

            if ((pDef == null) || (defs == null))
            {
               throw new RepositoryException("no propertyDefinition found");
            }

            if (pDef.getRequiredType() == PropertyType.BINARY)
            {
               newProperty = endBinary(propertiesMap, newProperty, propName);
            }
            else
            {
               StringTokenizer spaceTokenizer = new StringTokenizer(propertiesMap.get(propName));

               List<ValueData> values = new ArrayList<ValueData>();
               int pType = pDef.getRequiredType() > 0 ? pDef.getRequiredType() : PropertyType.STRING;
              
               if (defs.getAnyDefinition().isResidualSet())
               {
                  if (nodeData.getQPath().isDescendantOf(Constants.JCR_VERSION_STORAGE_PATH))
                  {
View Full Code Here

      if (curParent() == null)
      {
         NodeData existedParent = (NodeData)dataManager.getItemData(property.getParentIdentifier());

         PropertyDefinitionData pdef =
            ntManager.getPropertyDefinitions(property.getQPath().getName(), existedParent.getPrimaryTypeName(),
               existedParent.getMixinTypeNames()).getAnyDefinition();

         if (pdef.getOnParentVersion() == OnParentVersionAction.IGNORE)
         {
            // parent is not exists as this copy context current parent
            // i.e. it's a IGNOREd property elsewhere at a versionable node
            // descendant.
            // So, we have to know that this parent WILL exists after restore
View Full Code Here

      }
      else
      {
         NodeData parent = (NodeData)dataManager.getItemData(property.getParentIdentifier());

         PropertyDefinitionData pdef =
            ntManager.getPropertyDefinitions(qname, parent.getPrimaryTypeName(), parent.getMixinTypeNames())
               .getAnyDefinition();

         int action = pdef.getOnParentVersion();

         if (action == OnParentVersionAction.IGNORE)
         {
            return;
         }
         else if (action == OnParentVersionAction.ABORT)
         {
            throw new VersionException("Property is aborted " + property.getQPath().getAsString());
         }
         else if (action == OnParentVersionAction.COPY || action == OnParentVersionAction.VERSION
            || action == OnParentVersionAction.COMPUTE)
         {
            frozenProperty =
               TransientPropertyData.createPropertyData(currentNode(), qname, property.getType(), mv, values);
         }
         else if (action == OnParentVersionAction.INITIALIZE)
         {
            // 8.2.11.3 INITIALIZE
            // On checkin of N, a new P will be created and placed in version
            // storage as a child of VN. The new P will be initialized just as it
            // would
            // be if created normally in a workspace
            if (pdef.isAutoCreated())
            {
               if (pdef.getDefaultValues() != null && pdef.getDefaultValues().length > 0)
               {
                  // to use default values
                  values.clear();
                  for (String defValue : pdef.getDefaultValues())
                  {
                     ValueData defData;
                     if (PropertyType.UNDEFINED == pdef.getRequiredType())
                     {
                        defData = ((BaseValue)valueFactory.createValue(defValue)).getInternalData();
                     }
                     else
                     {
                        defData =
                           ((BaseValue)valueFactory.createValue(defValue, pdef.getRequiredType())).getInternalData();
                     }
                     // TransientValueData defData = ((BaseValue)
                     // defValue).getInternalData();
                     // values.add(defData.createTransientCopy());
                     values.add(defData);
View Full Code Here

         InternalQName iname = locationFactory.parseJCRName(itemName).getInternalName();

         PropertyDefinitionDatas pdefs = nodeTypeDataManager.getPropertyDefinitions(iname, nodeTypeData.getName());
         if (pdefs != null)
         {
            PropertyDefinitionData pd = pdefs.getAnyDefinition();
            if (pd != null)
               return !(pd.isMandatory() || pd.isProtected());
         }
         NodeDefinitionData cndef = nodeTypeDataManager.getChildNodeDefinition(iname, nodeTypeData.getName());
         if (cndef != null)
            return !(cndef.isMandatory() || cndef.isProtected());
View Full Code Here

         InternalQName pname = locationFactory.parseJCRName(propertyName).getInternalName();

         PropertyDefinitionDatas pdefs = nodeTypeDataManager.getPropertyDefinitions(pname, nodeTypeData.getName());
         if (pdefs != null)
         {
            PropertyDefinitionData pd = pdefs.getDefinition(false);
            if (pd != null)
            {
               if (pd.isProtected())
               {
                  // can set (edit)
                  return false;
               }
               else if (value != null)
               {
                  // can set (add or edit)
                  return canSetPropertyForType(pd.getRequiredType(), value, pd.getValueConstraints());
               }
               else
               {
                  // can remove
                  return !pd.isMandatory();
               }
            }
         }
         return false;
      }
View Full Code Here

      try
      {
         InternalQName pname = locationFactory.parseJCRName(propertyName).getInternalName();

         PropertyDefinitionDatas pdefs = nodeTypeDataManager.getPropertyDefinitions(pname, nodeTypeData.getName());
         PropertyDefinitionData pd = pdefs.getDefinition(true);
         if (pd != null)
         {
            if (pd.isProtected())
            {
               // can set (edit)
               return false;
            }
            else if (values != null)
            {
               // can set (add or edit)
               int res = 0;
               for (Value value : values)
               {
                  if (canSetPropertyForType(pd.getRequiredType(), value, pd.getValueConstraints()))
                  {
                     res++;
                  }
               }
               return res == values.length;
            }
            else
            {
               // can remove
               return !pd.isMandatory();
            }
         }
         else
         {
            return false;
View Full Code Here

      List<RelatedDefinition<PropertyDefinitionData>> changedDefinitionData, List<NodeData> nodesData,
      PropertyDefinitionData[] allRecipientDefinition) throws RepositoryException
   {
      for (RelatedDefinition<PropertyDefinitionData> relatedDefinitions : changedDefinitionData)
      {
         PropertyDefinitionData ancestorDefinitionData = relatedDefinitions.getAncestorDefinition();
         PropertyDefinitionData recipientDefinitionData = relatedDefinitions.getRecepientDefinition();
         // change from mandatory=false to mandatory = true
         if (!ancestorDefinitionData.isMandatory() && recipientDefinitionData.isMandatory())
         {
            checkMandatory(registeredNodeType, nodesData, recipientDefinitionData);

         }
         // No need to check protected
         // change from Protected=false to Protected = true
         // if (!ancestorDefinitionData.isProtected() &&
         // recipientDefinitionData.isProtected()) {
         // checkProtected(registeredNodeType, nodesData, recipientDefinitionData);
         // }
         // Required type change
         if (ancestorDefinitionData.getRequiredType() != recipientDefinitionData.getRequiredType()
            && recipientDefinitionData.getRequiredType() != PropertyType.UNDEFINED)
         {
            checkRequiredType(registeredNodeType, recipientDefinitionData, allRecipientDefinition, nodesData);
         }
         // ValueConstraints
         if (!Arrays.deepEquals(ancestorDefinitionData.getValueConstraints(), recipientDefinitionData
            .getValueConstraints()))
         {
            checkValueConstraints(registeredNodeType, recipientDefinitionData, allRecipientDefinition, nodesData);
         }
         // multiple change
         if (ancestorDefinitionData.isMultiple() && !recipientDefinitionData.isMultiple())
         {
            checkIsMultiple(registeredNodeType, recipientDefinitionData, allRecipientDefinition, nodesData);
         }

      }
View Full Code Here

         PropertyDefinitionData[] props = new PropertyDefinitionData[pdlist.size()];
         for (int i = 0; i < pdlist.size(); i++)
         {
            PropertyDefinitionValue v = pdlist.get(i);

            PropertyDefinitionData pd;
            pd =
               new PropertyDefinitionData(locationFactory.parseJCRName(v.getName()).getInternalName(), ntName, v
                  .isAutoCreate(), v.isMandatory(), v.getOnVersion(), v.isReadOnly(), v.getRequiredType(),
                  safeListToArray(v.getValueConstraints()), safeListToArray(v.getDefaultValueStrings()),
                  v.isMultiple());

            props[i] = pd;
View Full Code Here

TOP

Related Classes of org.exoplatform.services.jcr.core.nodetype.PropertyDefinitionData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.