Search in sources :

Example 1 with PropertyIntegerDefinitionImpl

use of org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIntegerDefinitionImpl in project copper-cms by PogeyanOSS.

the class CreateAndDeleteTypeTest method createPropertyDefinition.

private AbstractPropertyDefinition<?> createPropertyDefinition(PropertyType propertyType) {
    AbstractPropertyDefinition<?> result = null;
    switch(propertyType) {
        case BOOLEAN:
            result = new PropertyBooleanDefinitionImpl();
            break;
        case ID:
            result = new PropertyIdDefinitionImpl();
            break;
        case INTEGER:
            result = new PropertyIntegerDefinitionImpl();
            break;
        case DATETIME:
            result = new PropertyDateTimeDefinitionImpl();
            break;
        case DECIMAL:
            result = new PropertyDecimalDefinitionImpl();
            break;
        case HTML:
            result = new PropertyHtmlDefinitionImpl();
            break;
        case URI:
            result = new PropertyUriDefinitionImpl();
            break;
        default:
            result = new PropertyStringDefinitionImpl();
    }
    result.setPropertyType(propertyType);
    result.setId("tck:" + propertyType.value());
    result.setLocalName("tck:local_" + propertyType.value());
    result.setLocalNamespace("tck:testlocalnamespace");
    result.setDisplayName("TCK " + propertyType.value() + " propertry");
    result.setQueryName("tck:" + propertyType.value());
    result.setDescription("TCK " + propertyType.value() + " propertry");
    result.setCardinality(Cardinality.SINGLE);
    result.setUpdatability(Updatability.READWRITE);
    result.setIsInherited(false);
    result.setIsQueryable(false);
    result.setIsOrderable(false);
    result.setIsRequired(false);
    result.setIsOpenChoice(true);
    return result;
}
Also used : PropertyIntegerDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIntegerDefinitionImpl) PropertyUriDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyUriDefinitionImpl) PropertyIdDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIdDefinitionImpl) PropertyBooleanDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyBooleanDefinitionImpl) PropertyDateTimeDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDateTimeDefinitionImpl) PropertyDecimalDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDecimalDefinitionImpl) PropertyHtmlDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyHtmlDefinitionImpl) PropertyStringDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringDefinitionImpl)

Example 2 with PropertyIntegerDefinitionImpl

use of org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIntegerDefinitionImpl in project iaf by ibissource.

the class CmisUtils method xml2PropertyDefinition.

private static PropertyDefinition<?> xml2PropertyDefinition(Element propertyDefinitionXml) {
    MutablePropertyDefinition<?> definition = null;
    PropertyType type = PropertyType.fromValue(propertyDefinitionXml.getAttribute("propertyType"));
    switch(type) {
        case ID:
            definition = new PropertyIdDefinitionImpl();
            break;
        case BOOLEAN:
            definition = new PropertyBooleanDefinitionImpl();
            break;
        case DATETIME:
            definition = new PropertyDateTimeDefinitionImpl();
            break;
        case DECIMAL:
            definition = new PropertyDecimalDefinitionImpl();
            break;
        case INTEGER:
            definition = new PropertyIntegerDefinitionImpl();
            break;
        case HTML:
            definition = new PropertyHtmlDefinitionImpl();
            break;
        case URI:
            definition = new PropertyUriDefinitionImpl();
            break;
        case STRING:
        default:
            definition = new PropertyStringDefinitionImpl();
            break;
    }
    definition.setPropertyType(type);
    definition.setId(propertyDefinitionXml.getAttribute("id"));
    definition.setDisplayName(CmisUtils.parseStringAttr(propertyDefinitionXml, "displayName"));
    definition.setDescription(CmisUtils.parseStringAttr(propertyDefinitionXml, "description"));
    definition.setLocalName(CmisUtils.parseStringAttr(propertyDefinitionXml, "localName"));
    definition.setLocalNamespace(CmisUtils.parseStringAttr(propertyDefinitionXml, "localNamespace"));
    definition.setQueryName(CmisUtils.parseStringAttr(propertyDefinitionXml, "queryName"));
    if (propertyDefinitionXml.hasAttribute("cardinality")) {
        definition.setCardinality(Cardinality.valueOf(propertyDefinitionXml.getAttribute("cardinality")));
    }
    if (propertyDefinitionXml.hasAttribute("updatability")) {
        definition.setUpdatability(Updatability.valueOf(propertyDefinitionXml.getAttribute("updatability")));
    }
    definition.setIsInherited(CmisUtils.parseBooleanAttr(propertyDefinitionXml, "inherited"));
    definition.setIsOpenChoice(CmisUtils.parseBooleanAttr(propertyDefinitionXml, "openChoice"));
    definition.setIsOrderable(CmisUtils.parseBooleanAttr(propertyDefinitionXml, "orderable"));
    definition.setIsQueryable(CmisUtils.parseBooleanAttr(propertyDefinitionXml, "queryable"));
    definition.setIsRequired(CmisUtils.parseBooleanAttr(propertyDefinitionXml, "required"));
    if (propertyDefinitionXml.hasAttribute("defaultValue")) {
        // TODO: turn this into a list
        List defaultValues = new ArrayList();
        String defaultValue = propertyDefinitionXml.getAttribute("defaultValue");
        defaultValues.add(defaultValue);
        definition.setDefaultValue(defaultValues);
    }
    return definition;
}
Also used : PropertyIntegerDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIntegerDefinitionImpl) PropertyIdDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIdDefinitionImpl) ArrayList(java.util.ArrayList) PropertyDateTimeDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDateTimeDefinitionImpl) PropertyType(org.apache.chemistry.opencmis.commons.enums.PropertyType) PropertyHtmlDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyHtmlDefinitionImpl) PropertyString(org.apache.chemistry.opencmis.commons.data.PropertyString) PropertyUriDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyUriDefinitionImpl) PropertyBooleanDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyBooleanDefinitionImpl) PropertyDecimalDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDecimalDefinitionImpl) ObjectInFolderList(org.apache.chemistry.opencmis.commons.data.ObjectInFolderList) PolicyIdList(org.apache.chemistry.opencmis.commons.data.PolicyIdList) ArrayList(java.util.ArrayList) ObjectList(org.apache.chemistry.opencmis.commons.data.ObjectList) List(java.util.List) PropertyStringDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringDefinitionImpl)

Example 3 with PropertyIntegerDefinitionImpl

use of org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIntegerDefinitionImpl in project iaf by ibissource.

the class CmisUtils method processProperties.

public static Properties processProperties(Element cmisElement) {
    PropertiesImpl properties = new PropertiesImpl();
    Element propertiesElement = XmlUtils.getFirstChildTag(cmisElement, "properties");
    Iterator<Node> propertyIterator = XmlUtils.getChildTags(propertiesElement, "property").iterator();
    while (propertyIterator.hasNext()) {
        Element propertyElement = (Element) propertyIterator.next();
        String propertyValue = XmlUtils.getStringValue(propertyElement);
        String nameAttr = propertyElement.getAttribute("name");
        String typeAttr = propertyElement.getAttribute("type");
        PropertyType propertyType = PropertyType.STRING;
        if (StringUtils.isNotEmpty(typeAttr)) {
            propertyType = PropertyType.fromValue(typeAttr);
        }
        if (StringUtils.isEmpty(typeAttr) && nameAttr.startsWith("cmis:")) {
            propertyType = PropertyType.ID;
        }
        boolean isNull = Boolean.parseBoolean(propertyElement.getAttribute("isNull"));
        if (isNull)
            propertyValue = null;
        switch(propertyType) {
            case ID:
                properties.addProperty(new PropertyIdImpl(addStandardDefinitions(new PropertyIdDefinitionImpl(), propertyElement, propertyType), propertyValue));
                break;
            case STRING:
                properties.addProperty(new PropertyStringImpl(addStandardDefinitions(new PropertyStringDefinitionImpl(), propertyElement, propertyType), propertyValue));
                break;
            case INTEGER:
                BigInteger bigInt = null;
                if (StringUtils.isNotEmpty(propertyValue)) {
                    bigInt = new BigInteger(propertyValue);
                }
                properties.addProperty(new PropertyIntegerImpl(addStandardDefinitions(new PropertyIntegerDefinitionImpl(), propertyElement, propertyType), bigInt));
                break;
            case DATETIME:
                GregorianCalendar gregorian = null;
                if (StringUtils.isNotEmpty(propertyValue)) {
                    String formatStringAttr = propertyElement.getAttribute("formatString");
                    String timezoneAttr = propertyElement.getAttribute("timezone");
                    if (StringUtils.isEmpty(formatStringAttr)) {
                        formatStringAttr = CmisUtils.FORMATSTRING_BY_DEFAULT;
                    }
                    DateFormat df = new SimpleDateFormat(formatStringAttr);
                    try {
                        Date date = df.parse(propertyValue);
                        gregorian = new GregorianCalendar();
                        gregorian.setTime(date);
                        if (StringUtils.isNotEmpty(timezoneAttr)) {
                            gregorian.setTimeZone(TimeZone.getTimeZone(timezoneAttr));
                        }
                    } catch (ParseException e) {
                        log.warn("exception parsing date [" + propertyValue + "] using formatString [" + formatStringAttr + "]", e);
                    }
                }
                properties.addProperty(new PropertyDateTimeImpl(addStandardDefinitions(new PropertyDateTimeDefinitionImpl(), propertyElement, propertyType), gregorian));
                break;
            case BOOLEAN:
                Boolean bool = null;
                if (StringUtils.isNotEmpty(propertyValue)) {
                    bool = Boolean.parseBoolean(propertyValue);
                }
                properties.addProperty(new PropertyBooleanImpl(addStandardDefinitions(new PropertyBooleanDefinitionImpl(), propertyElement, propertyType), bool));
                break;
            case DECIMAL:
                BigDecimal decimal = null;
                if (StringUtils.isNotEmpty(propertyValue)) {
                    decimal = new BigDecimal(propertyValue);
                }
                properties.addProperty(new PropertyDecimalImpl(addStandardDefinitions(new PropertyDecimalDefinitionImpl(), propertyElement, propertyType), decimal));
                break;
            case URI:
                properties.addProperty(new PropertyUriImpl(addStandardDefinitions(new PropertyUriDefinitionImpl(), propertyElement, propertyType), propertyValue));
                break;
            case HTML:
                properties.addProperty(new PropertyHtmlImpl(addStandardDefinitions(new PropertyHtmlDefinitionImpl(), propertyElement, propertyType), propertyValue));
                break;
            default:
                log.warn("unparsable type [" + typeAttr + "] for property [" + propertyValue + "]");
                // Skip all and continue with the next property!
                continue;
        }
        log.debug("set property name [" + nameAttr + "] value [" + propertyValue + "]");
    }
    return properties;
}
Also used : Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) PropertyDateTimeDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDateTimeDefinitionImpl) PropertyString(org.apache.chemistry.opencmis.commons.data.PropertyString) PropertyType(org.apache.chemistry.opencmis.commons.enums.PropertyType) PropertyHtmlImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyHtmlImpl) PropertyIntegerImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIntegerImpl) PropertyStringImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringImpl) PropertyBooleanDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyBooleanDefinitionImpl) PropertyUriImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyUriImpl) PropertyDecimalImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDecimalImpl) PropertyBoolean(org.apache.chemistry.opencmis.commons.data.PropertyBoolean) PropertyStringDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringDefinitionImpl) PropertyIntegerDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIntegerDefinitionImpl) PropertiesImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl) PropertyIdDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIdDefinitionImpl) PropertyDateTimeImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDateTimeImpl) GregorianCalendar(java.util.GregorianCalendar) PropertyHtmlDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyHtmlDefinitionImpl) Date(java.util.Date) PropertyBooleanImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyBooleanImpl) BigDecimal(java.math.BigDecimal) PropertyIdImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIdImpl) PropertyUriDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyUriDefinitionImpl) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) BigInteger(java.math.BigInteger) PropertyDecimalDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDecimalDefinitionImpl) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 4 with PropertyIntegerDefinitionImpl

use of org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIntegerDefinitionImpl in project alfresco-repository by Alfresco.

the class CMISTest method testIntegerBoudaries.

/**
 * Test for MNT-9089
 */
@Test
public void testIntegerBoudaries() throws Exception {
    AuthenticationUtil.pushAuthentication();
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    try {
        final FileInfo fileInfo = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<FileInfo>() {

            @Override
            public FileInfo execute() throws Throwable {
                NodeRef companyHomeNodeRef = repositoryHelper.getCompanyHome();
                QName testIntTypeQName = QName.createQName("http://testCMISIntegersModel/1.0/", "testintegerstype");
                String folderName = GUID.generate();
                FileInfo folderInfo = fileFolderService.create(companyHomeNodeRef, folderName, ContentModel.TYPE_FOLDER);
                nodeService.setProperty(folderInfo.getNodeRef(), ContentModel.PROP_NAME, folderName);
                assertNotNull(folderInfo);
                String docName = GUID.generate();
                FileInfo fileInfo = fileFolderService.create(folderInfo.getNodeRef(), docName, testIntTypeQName);
                assertNotNull(fileInfo);
                nodeService.setProperty(fileInfo.getNodeRef(), ContentModel.PROP_NAME, docName);
                return fileInfo;
            }
        });
        // get repository id
        withCmisService(new CmisServiceCallback<Void>() {

            @Override
            public Void execute(CmisService cmisService) {
                List<RepositoryInfo> repositories = cmisService.getRepositoryInfos(null);
                assertTrue(repositories.size() > 0);
                RepositoryInfo repo = repositories.get(0);
                String repositoryId = repo.getId();
                String objectIdStr = fileInfo.getNodeRef().toString();
                TypeDefinition typeDef = cmisService.getTypeDefinition(repositoryId, "D:tcim:testintegerstype", null);
                PropertyIntegerDefinitionImpl intNoBoundsTypeDef = (PropertyIntegerDefinitionImpl) typeDef.getPropertyDefinitions().get("tcim:int");
                PropertyIntegerDefinitionImpl longNoBoundsTypeDef = (PropertyIntegerDefinitionImpl) typeDef.getPropertyDefinitions().get("tcim:long");
                PropertyIntegerDefinitionImpl intWithBoundsTypeDef = (PropertyIntegerDefinitionImpl) typeDef.getPropertyDefinitions().get("tcim:intwithbounds");
                PropertyIntegerDefinitionImpl longWithBoundsTypeDef = (PropertyIntegerDefinitionImpl) typeDef.getPropertyDefinitions().get("tcim:longwithbounds");
                BigInteger minInteger = BigInteger.valueOf(Integer.MIN_VALUE);
                BigInteger maxInteger = BigInteger.valueOf(Integer.MAX_VALUE);
                BigInteger minLong = BigInteger.valueOf(Long.MIN_VALUE);
                BigInteger maxLong = BigInteger.valueOf(Long.MAX_VALUE);
                // test for default boundaries
                assertTrue(intNoBoundsTypeDef.getMinValue().equals(minInteger));
                assertTrue(intNoBoundsTypeDef.getMaxValue().equals(maxInteger));
                assertTrue(longNoBoundsTypeDef.getMinValue().equals(minLong));
                assertTrue(longNoBoundsTypeDef.getMaxValue().equals(maxLong));
                // test for pre-defined boundaries
                assertTrue(intWithBoundsTypeDef.getMinValue().equals(BigInteger.valueOf(-10L)));
                assertTrue(intWithBoundsTypeDef.getMaxValue().equals(BigInteger.valueOf(10L)));
                assertTrue(longWithBoundsTypeDef.getMinValue().equals(BigInteger.valueOf(-10L)));
                assertTrue(longWithBoundsTypeDef.getMaxValue().equals(BigInteger.valueOf(10L)));
                try // try to overfloat long without boundaries
                {
                    BigInteger aValue = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.valueOf(1L));
                    setProperiesToObject(cmisService, repositoryId, objectIdStr, "tcim:long", aValue);
                    fail();
                } catch (Exception e) {
                    assertTrue(e instanceof CmisConstraintException);
                }
                try // try to overfloat int without boundaries
                {
                    BigInteger aValue = BigInteger.valueOf(Integer.MAX_VALUE).add(BigInteger.valueOf(1L));
                    setProperiesToObject(cmisService, repositoryId, objectIdStr, "tcim:int", aValue);
                    fail();
                } catch (Exception e) {
                    assertTrue(e instanceof CmisConstraintException);
                }
                try // try to overfloat int with boundaries
                {
                    BigInteger aValue = BigInteger.valueOf(11l);
                    setProperiesToObject(cmisService, repositoryId, objectIdStr, "tcim:intwithbounds", aValue);
                    fail();
                } catch (Exception e) {
                    assertTrue(e instanceof CmisConstraintException);
                }
                try // try to overfloat long with boundaries
                {
                    BigInteger aValue = BigInteger.valueOf(11l);
                    setProperiesToObject(cmisService, repositoryId, objectIdStr, "tcim:longwithbounds", aValue);
                    fail();
                } catch (Exception e) {
                    assertTrue(e instanceof CmisConstraintException);
                }
                return null;
            }
        }, CmisVersion.CMIS_1_0);
    } catch (Exception e) {
        fail(e.getMessage());
    } finally {
        AuthenticationUtil.popAuthentication();
    }
}
Also used : PropertyIntegerDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIntegerDefinitionImpl) RepositoryInfo(org.apache.chemistry.opencmis.commons.data.RepositoryInfo) QName(org.alfresco.service.namespace.QName) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisUpdateConflictException(org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) IOException(java.io.IOException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TypeDefinition(org.apache.chemistry.opencmis.commons.definitions.TypeDefinition) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) CmisService(org.apache.chemistry.opencmis.commons.server.CmisService) BigInteger(java.math.BigInteger) ObjectInFolderList(org.apache.chemistry.opencmis.commons.data.ObjectInFolderList) ArrayList(java.util.ArrayList) ObjectList(org.apache.chemistry.opencmis.commons.data.ObjectList) List(java.util.List) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Aggregations

PropertyIntegerDefinitionImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIntegerDefinitionImpl)4 PropertyBooleanDefinitionImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyBooleanDefinitionImpl)3 PropertyDateTimeDefinitionImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDateTimeDefinitionImpl)3 PropertyDecimalDefinitionImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDecimalDefinitionImpl)3 PropertyHtmlDefinitionImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyHtmlDefinitionImpl)3 PropertyIdDefinitionImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIdDefinitionImpl)3 PropertyStringDefinitionImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringDefinitionImpl)3 BigInteger (java.math.BigInteger)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ObjectInFolderList (org.apache.chemistry.opencmis.commons.data.ObjectInFolderList)2 ObjectList (org.apache.chemistry.opencmis.commons.data.ObjectList)2 PropertyString (org.apache.chemistry.opencmis.commons.data.PropertyString)2 PropertyType (org.apache.chemistry.opencmis.commons.enums.PropertyType)2 PropertyUriDefinitionImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyUriDefinitionImpl)2 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 BigDecimal (java.math.BigDecimal)1 DateFormat (java.text.DateFormat)1 ParseException (java.text.ParseException)1