Java Code Examples for org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter

The following examples show how to use org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
protected void evaluateSingleValue(Object value)
{
    // ensure that the value can be converted to a String
    String checkValue = null;
    try
    {
        checkValue = DefaultTypeConverter.INSTANCE.convert(String.class, value);
    }
    catch (TypeConversionException e)
    {
        throw new ConstraintException(ERR_NON_STRING, value);
    }
    
    AuthorityType type = AuthorityType.getAuthorityType(checkValue);
    if((type != AuthorityType.GROUP) && (type != AuthorityType.ROLE))
    {
        throw new ConstraintException(ERR_INVALID_AUTHORITY_NAME, value, type);
    }
}
 
Example 2
@Override
protected void evaluateSingleValue(Object value)
{
    // ensure that the value can be converted to a String
    String checkValue = null;
    try
    {
        checkValue = DefaultTypeConverter.INSTANCE.convert(String.class, value);
    }
    catch (TypeConversionException e)
    {
        throw new ConstraintException(ERR_NON_STRING, value);
    }
    
    AuthorityType type = AuthorityType.getAuthorityType(checkValue);
    if((type != AuthorityType.USER) && (type != AuthorityType.GUEST))
    {
        throw new ConstraintException(ERR_INVALID_USERNAME, value, type);
    }
}
 
Example 3
public Q addComponent(Set<String> selectors, Map<String, Argument> functionArgs, LuceneQueryBuilderContext<Q, S, E> luceneContext, FunctionEvaluationContext functionContext)
        throws E
{
    LuceneQueryParserAdaptor<Q, S, E> lqpa = luceneContext.getLuceneQueryParserAdaptor();
    PropertyArgument propertyArgument = (PropertyArgument) functionArgs.get(ARG_PROPERTY);
    Argument inverseArgument = functionArgs.get(ARG_NOT);
    Boolean not = DefaultTypeConverter.INSTANCE.convert(Boolean.class, inverseArgument.getValue(functionContext));

    Q query = functionContext.buildLuceneExists(lqpa, propertyArgument.getPropertyName(), not);

    if (query == null)
    {
        throw new QueryModelException("No query time mapping for property  " + propertyArgument.getPropertyName() + ", it should not be allowed in predicates");
    }

    return query;
}
 
Example 4
/**
 * @param userName          the username
 * @param properties        user properties or <tt>null</tt> to fetch them
 */
protected boolean getCredentialsExpire(String userName, Map<QName, Serializable> properties)
{
    if (authorityService.isAdminAuthority(userName))
    {
        return false;            // Admin never expires
    }
    if (properties == null)
    {
        properties = getUserProperties(userName);
    }
    if (properties == null)
    {
        return false;
    }
    Serializable ser = properties.get(ContentModel.PROP_CREDENTIALS_EXPIRE);
    if (ser == null)
    {
        return false;
    }
    else
    {
        return DefaultTypeConverter.INSTANCE.booleanValue(ser);
    }
}
 
Example 5
@Override
public Date getCredentialsExpiryDate(String userName)
{
    NodeRef userNode = getUserOrNull(userName);
    if (userNode == null)
    {
        return null;
    }
    if (DefaultTypeConverter.INSTANCE.booleanValue(nodeService.getProperty(userNode, ContentModel.PROP_CREDENTIALS_EXPIRE)))
    {
        return DefaultTypeConverter.INSTANCE.convert(Date.class, nodeService.getProperty(userNode, ContentModel.PROP_CREDENTIALS_EXPIRY_DATE));
    }
    else
    {
        return null;
    }
}
 
Example 6
/**
 * We also provide the creation date - check that
 */
protected void testFileSpecificMetadata(String mimetype,
      Map<QName, Serializable> properties) 
{
   // Check for extra fields
   assertEquals(
         "Property " + ContentModel.PROP_AUTHOR + " not found for mimetype " + mimetype,
         "Nevin Nollop",
         DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_AUTHOR)));
   
   // Ensure that we can also get things which are standard
   //  Tika metadata properties, if we so choose to
   assertTrue( 
         "Test Property " + TIKA_LAST_AUTHOR_TEST_PROPERTY + " not found for mimetype " + mimetype,
         properties.containsKey(TIKA_LAST_AUTHOR_TEST_PROPERTY)
   );
   assertEquals(
         "Test Property " + TIKA_LAST_AUTHOR_TEST_PROPERTY + " incorrect for mimetype " + mimetype,
         "paolon",
         DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(TIKA_LAST_AUTHOR_TEST_PROPERTY)));
}
 
Example 7
public void removeAuthorityFromZones(String authorityName, Set<String> zones)
{
    if ((zones != null) && (zones.size() > 0))
    {
        NodeRef authRef = getAuthorityOrNull(authorityName);
        List<ChildAssociationRef> results = nodeService.getParentAssocs(authRef, ContentModel.ASSOC_IN_ZONE, RegexQNamePattern.MATCH_ALL);
        for (ChildAssociationRef current : results)
        {
            NodeRef zoneRef = current.getParentRef();
            Serializable value = nodeService.getProperty(zoneRef, ContentModel.PROP_NAME);
            if (value == null)
            {
                continue;
            }
            else
            {
                String testZone = DefaultTypeConverter.INSTANCE.convert(String.class, value);
                if (zones.contains(testZone))
                {
                    nodeService.removeChildAssociation(current);
                }
            }
        }
    }
}
 
Example 8
@Before
public void before()
{
    AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();

    // cleanup all existing people, the test is sensitive to the user names
    transactionService.getRetryingTransactionHelper().doInTransaction(() -> {
        for (NodeRef nodeRef : personService.getAllPeople())
        {
            String uid = DefaultTypeConverter.INSTANCE.convert(String.class, nodeService.getProperty(nodeRef, ContentModel.PROP_USERNAME));
            if (!uid.equals(AuthenticationUtil.getAdminUserName()) && !uid.equals(AuthenticationUtil.getGuestUserName()))
            {
                personService.deletePerson(nodeRef);
            }
        }
        return null;
    });

}
 
Example 9
public void testHtmlExtractionJapanese() throws Exception
{
    String mimetype = MimetypeMap.MIMETYPE_HTML;

    File japaneseHtml = AbstractContentTransformerTest.loadNamedQuickTestFile("quick.japanese.html");
    Map<QName, Serializable> properties = extractFromFile(japaneseHtml, mimetype);

    assertFalse("extractFromMimetype should return at least some properties, none found for " + mimetype,
            properties.isEmpty());

    // Title and description
    assertEquals(
            "Property " + ContentModel.PROP_TITLE + " not found for mimetype " + mimetype,
            QUICK_TITLE_JAPANESE,
            DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_TITLE)));
}
 
Example 10
@SuppressWarnings("unused")
public void testCreateEmptyTranslation() throws Exception
{
    NodeRef chineseContentNodeRef = createContent("Document.txt");
    multilingualContentService.makeTranslation(chineseContentNodeRef, Locale.CHINESE);

    // This should use the pivot language
    NodeRef emptyNodeRef = multilingualContentService.addEmptyTranslation(chineseContentNodeRef, "Document.txt", Locale.CANADA);

    // Ensure that the empty translation is not null
    assertNotNull("The creation of the empty document failed ", emptyNodeRef);
    // Ensure that the empty translation has the mlDocument aspect
    assertTrue("The empty document must have the mlDocument aspect",
            nodeService.hasAspect(emptyNodeRef, ContentModel.ASPECT_MULTILINGUAL_DOCUMENT));
    // Ensure that the empty translation has the mlEmptyTranslation aspect
    assertTrue("The empty document must have the mlEmptyTranslation aspect",
            nodeService.hasAspect(emptyNodeRef, ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION));
    // Check that the auto renaming worked
    String emptyName = DefaultTypeConverter.INSTANCE.convert(String.class,
            nodeService.getProperty(emptyNodeRef, ContentModel.PROP_NAME));
    assertEquals("Empty auto-rename didn't work for same-named document", "Document_en_CA.txt", emptyName);

    // Check that the content is identical
    ContentData chineseContentData = fileFolderService.getReader(chineseContentNodeRef).getContentData();
    ContentData emptyContentData = fileFolderService.getReader(emptyNodeRef).getContentData();
}
 
Example 11
protected void evaluateSingleValue(Object value)
{
    // ensure that the value can be converted to a double
    double checkValue = Double.NaN;
    try
    {
        checkValue = DefaultTypeConverter.INSTANCE.doubleValue(value);
    }
    catch (NumberFormatException e)
    {
        throw new ConstraintException(ERR_NON_NUMERIC, value);
    }
    
    // Infinity and NaN cannot match
    if (Double.isInfinite(checkValue) || Double.isNaN(checkValue))
    {
        throw new ConstraintException(ERR_OUT_OF_RANGE, checkValue, minValue, maxValue);
    }
    
    // Check that the value is in range
    if (checkValue > maxValue || checkValue < minValue)
    {
        throw new ConstraintException(ERR_OUT_OF_RANGE, checkValue, minValue, maxValue);
    }
}
 
Example 12
protected void evaluateSingleValue(Object value)
{
    // ensure that the value can be converted to a String
    String checkValue = null;
    try
    {
        checkValue = DefaultTypeConverter.INSTANCE.convert(String.class, value);
    }
    catch (TypeConversionException e)
    {
        throw new ConstraintException(ERR_NON_STRING, value);
    }
    
    // Check that the value length
    int length = checkValue.length();
    if (length > maxLength || length < minLength)
    {
        if (length > 20)
        {
            checkValue = checkValue.substring(0, 17) + "...";
        }
        throw new ConstraintException(ERR_INVALID_LENGTH, checkValue, minLength, maxLength);
    }
}
 
Example 13
public String getOwner(NodeRef nodeRef)
{
    String userName = nodeOwnerCache.get(nodeRef);

    if (userName == null)
    {
        // If ownership is not explicitly set then we fall back to the creator
        if (isRendition(nodeRef))
        {
            userName = getOwner(nodeService.getPrimaryParent(nodeRef).getParentRef());
        }
        else if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_OWNABLE))
        {
            userName = DefaultTypeConverter.INSTANCE.convert(String.class, nodeService.getProperty(nodeRef, ContentModel.PROP_OWNER));
        }
        else if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_AUDITABLE))
        {
            userName = DefaultTypeConverter.INSTANCE.convert(String.class, nodeService.getProperty(nodeRef, ContentModel.PROP_CREATOR));
        }
        cacheOwner(nodeRef, userName);
    }

    return userName;
}
 
Example 14
private <Q, S, E extends Throwable> String getValueAsString(LuceneQueryParserAdaptor<Q, S, E> lqpa, Serializable value)
{
	String nodeRefStr = null;
    if(!NodeRef.isNodeRef((String)value))
    {
        // assume the object id is the node guid
        StoreRef storeRef = getStore(lqpa);
    	nodeRefStr = storeRef.toString() + "/" + (String)value;
    }
    else
    {
    	nodeRefStr = (String)value;
    }

    Object converted = DefaultTypeConverter.INSTANCE.convert(dictionaryService.getDataType(DataTypeDefinition.NODE_REF), nodeRefStr);
    String asString = DefaultTypeConverter.INSTANCE.convert(String.class, converted);
    return asString;
}
 
Example 15
/**
 * We don't have quite the usual metadata. Tests the descriptions one.
 * Other tests in {@link #testFileSpecificMetadata(String, Map)}
 */
protected void testCommonMetadata(String mimetype, Map<QName, Serializable> properties) 
{
   // Title is as normal
   assertEquals(
         "Property " + ContentModel.PROP_TITLE + " not found for mimetype " + mimetype,
         QUICK_TITLE,
         DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_TITLE)));
   // Has Author, not Creator, and is different
   assertEquals(
         "Property " + ContentModel.PROP_AUTHOR + " not found for mimetype " + mimetype,
         "Hauskaz",
         DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_AUTHOR)));
   
   // Description is a composite
   assertContains(
         "Property " + ContentModel.PROP_DESCRIPTION + " didn't contain " +  QUICK_TITLE + " for mimetype " + mimetype,
         QUICK_TITLE,
         DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_DESCRIPTION)));
   // Check rest of it later
}
 
Example 16
@Override
Serializable convert(Serializable value)
{
    if (value == null)
    {
        return null;
    }
    else if (value instanceof ContentDataId)
    {
        return ((ContentDataId)value).getId();
    }
    else if (value instanceof ContentDataWithId)
    {
        return ((ContentDataWithId)value).getId();
    }
    else
    {
        return DefaultTypeConverter.INSTANCE.convert(Long.class, value);
    }
}
 
Example 17
/**
 * Returns the hash code of the source node's content url. As transformations may be returned in a different
 * sequences to which they were requested, this is used work out if a rendition should be replaced.
 */
private int getSourceContentHashCode(NodeRef sourceNodeRef)
{
    int hashCode = SOURCE_HAS_NO_CONTENT;
    ContentData contentData = DefaultTypeConverter.INSTANCE.convert(ContentData.class, nodeService.getProperty(sourceNodeRef, PROP_CONTENT));
    if (contentData != null)
    {
        // Originally we used the contentData URL, but that is not enough if the mimetype changes.
        String contentString = contentData.getContentUrl()+contentData.getMimetype();
        if (contentString != null)
        {
            hashCode = contentString.hashCode();
        }
    }
    return hashCode;
}
 
Example 18
protected ContentData getContentData(CMISNodeInfo nodeInfo)
{
    if (!nodeInfo.isDocument())
    {
        return null;
    }

    if (nodeInfo.containsPropertyValue(CONTENT_PROPERTY))
    {
        return (ContentData) nodeInfo.getPropertyValue(CONTENT_PROPERTY);
    } else
    {
        ContentData contentData = null;

        Serializable value = nodeInfo.getNodeProps().get(ContentModel.PROP_CONTENT);

        if (value != null)
        {
            contentData = DefaultTypeConverter.INSTANCE.convert(ContentData.class, value);
        }

        nodeInfo.putPropertyValue(CONTENT_PROPERTY, contentData);
        return contentData;
    }
}
 
Example 19
@Test
public void changedSourceToNonNull()
{
    NodeRef sourceNodeRef = createSource(ADMIN, "quick.jpg");
    render(ADMIN, sourceNodeRef, DOC_LIB);
    NodeRef rendition1 = waitForRendition(ADMIN, sourceNodeRef, DOC_LIB, true);
    ContentData contentData1 = DefaultTypeConverter.INSTANCE.convert(ContentData.class, nodeService.getProperty(rendition1, PROP_CONTENT));

    updateContent(ADMIN, sourceNodeRef, "quick.png");
    render(ADMIN, sourceNodeRef, DOC_LIB);
    NodeRef rendition2 = waitForRendition(ADMIN, sourceNodeRef, DOC_LIB, true);
    ContentData contentData2 = DefaultTypeConverter.INSTANCE.convert(ContentData.class, nodeService.getProperty(rendition2, PROP_CONTENT));

    assertEquals("The rendition node should not change", rendition1, rendition2);
    assertNotEquals("The content should have change", contentData1.toString(), contentData2.toString());
}
 
Example 20
/**
 * @param userName          the username
 * @param properties        user properties or <tt>null</tt> to fetch them
 */
protected boolean getHasExpired(String userName, Map<QName, Serializable> properties, Boolean isAdminAuthority)
{
    if (isAdminAuthority == null)
    {
        isAdminAuthority = authorityService.isAdminAuthority(userName);
    }
    if (isAdminAuthority)
    {
        return false;            // Admin never expires
    }
    if (properties == null)
    {
        properties = getUserProperties(userName);
    }
    if (properties == null)
    {
        return false;
    }
    if (DefaultTypeConverter.INSTANCE.booleanValue(properties.get(ContentModel.PROP_ACCOUNT_EXPIRES)))
    {
        Date date = DefaultTypeConverter.INSTANCE.convert(Date.class, properties.get(ContentModel.PROP_ACCOUNT_EXPIRY_DATE));
        if (date == null)
        {
            return false;
        }
        else
        {
            return (date.getTime() < System.currentTimeMillis());
        }
    }
    else
    {
        return false;
    }
}
 
Example 21
/**
 * @param userName          the username
 * @param properties        user properties or <tt>null</tt> to fetch them
 */
protected boolean getLocked(String userName, Map<QName, Serializable> properties, Boolean isAdminAuthority)
{
    if (isAdminAuthority == null)
    {
        isAdminAuthority = authorityService.isAdminAuthority(userName);
    }
    if (isAdminAuthority)
    {
        return false;            // Admin is never locked
    }
    if (properties == null)
    {
        properties = getUserProperties(userName);
    }
    if (properties == null)
    {
        return false;
    }
    Serializable ser = properties.get(ContentModel.PROP_ACCOUNT_LOCKED);
    if (ser == null)
    {
        return false;
    }
    else
    {
        return DefaultTypeConverter.INSTANCE.booleanValue(ser);
    }
}
 
Example 22
protected String getValueAsString(Serializable value)
{
    Object converted = DefaultTypeConverter.INSTANCE.convert(getServiceRegistry().getDictionaryService()
            .getDataType(DataTypeDefinition.TEXT), value);
    String asString = DefaultTypeConverter.INSTANCE.convert(String.class, converted);
    return asString;
}
 
Example 23
/**
 * Tests that we can get the common metadata correctly
 *  from the file.
 * You only need to override this if your test data file
 *  doesn't have the usual Nevin Nollop/quick brown fox 
 *  data in it.
 */
protected void testCommonMetadata(String mimetype, Map<QName, Serializable> properties)
{
   // One of Creator or Author
   if(!skipAuthorCheck(mimetype)) 
   {
      if(properties.containsKey(ContentModel.PROP_CREATOR)) 
      {
         assertEquals(
               "Property " + ContentModel.PROP_CREATOR + " not found for mimetype " + mimetype,
               QUICK_CREATOR,
               DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_CREATOR)));
      } 
      else if(properties.containsKey(ContentModel.PROP_AUTHOR)) 
      {
         assertEquals(
               "Property " + ContentModel.PROP_AUTHOR + " not found for mimetype " + mimetype,
               QUICK_CREATOR,
               DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_AUTHOR)));
      } 
      else 
      {
         fail("Expected one property out of " + ContentModel.PROP_CREATOR + " and " + 
               ContentModel.PROP_AUTHOR + " but found neither of them for " + mimetype);
      }
   }
   
   // Title and description
   assertEquals(
            "Property " + ContentModel.PROP_TITLE + " not found for mimetype " + mimetype,
            QUICK_TITLE,
            DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_TITLE)));
   if (!skipDescriptionCheck(mimetype)) 
   {
       assertEquals(
               "Property " + ContentModel.PROP_DESCRIPTION + " not found for mimetype " + mimetype,
               QUICK_DESCRIPTION,
               DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_DESCRIPTION)));
   }
}
 
Example 24
public void onUpdateUserProperties(NodeRef nodeRef, Map<QName, Serializable> before, Map<QName, Serializable> after)
{
    String uidBefore = DefaultTypeConverter.INSTANCE.convert(String.class, before.get(ContentModel.PROP_USER_USERNAME));
    if (uidBefore != null)
    {
        removeAuthenticationFromCache(uidBefore);
    }
}
 
Example 25
public String getAuthorityDisplayName(String authorityName)
{
    NodeRef ref = getAuthorityOrNull(authorityName);
    if (ref == null)
    {
        return null;
    }
    Serializable value = nodeService.getProperty(ref, ContentModel.PROP_AUTHORITY_DISPLAY_NAME);
    if (value == null)
    {
        return null;
    }
    return DefaultTypeConverter.INSTANCE.convert(String.class, value);
}
 
Example 26
public Set<String> getAuthorityZones(String name)
{
    Set<String> zones = new TreeSet<String>();
    NodeRef childRef = getAuthorityOrNull(name);
    if (childRef == null)
    {
        return null;
    }
    List<ChildAssociationRef> results = nodeService.getParentAssocs(childRef, ContentModel.ASSOC_IN_ZONE, RegexQNamePattern.MATCH_ALL);
    if (results.isEmpty())
    {
        return zones;
    }

    for (ChildAssociationRef current : results)
    {
        NodeRef zoneRef = current.getParentRef();
        Serializable value = nodeService.getProperty(zoneRef, ContentModel.PROP_NAME);
        if (value == null)
        {
            continue;
        }
        else
        {
            String zone = DefaultTypeConverter.INSTANCE.convert(String.class, value);
            zones.add(zone);
        }
    }
    return zones;
}
 
Example 27
protected ContentStore selectStoreForCurrentContext()
{
    final String site = DefaultTypeConverter.INSTANCE.convert(String.class,
            ContentStoreContext.getContextAttribute(ContentStoreContext.DEFAULT_ATTRIBUTE_SITE));
    final String sitePreset = DefaultTypeConverter.INSTANCE.convert(String.class,
            ContentStoreContext.getContextAttribute(ContentStoreContext.DEFAULT_ATTRIBUTE_SITE_PRESET));

    return this.resolveStoreForSite(site, sitePreset);
}
 
Example 28
@Override
protected String getValueAsString(Serializable value)
{
    Object converted = DefaultTypeConverter.INSTANCE.convert(dictionaryService.getDataType(DataTypeDefinition.TEXT), value);
    String asString = DefaultTypeConverter.INSTANCE.convert(String.class, converted);
    return asString;
}
 
Example 29
private void makeHomeFolderIfRequired(NodeRef person)
{
    if ((person != null) && (homeFolderCreationDisabled == false))
    {
        NodeRef homeFolder = DefaultTypeConverter.INSTANCE.convert(NodeRef.class, nodeService.getProperty(person, ContentModel.PROP_HOMEFOLDER));
        if (homeFolder == null)
        {
            final ChildAssociationRef ref = nodeService.getPrimaryParent(person);
            RetryingTransactionHelper txnHelper = transactionService.getRetryingTransactionHelper();
            txnHelper.setForceWritable(true);
            boolean requiresNew = false;
            if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_READ_WRITE)
            {
                // We can be in a read-only transaction, so force a new transaction
                // Note that the transaction will *always* be in read-only mode if the server read-only veto is there 
                requiresNew = true;
            }
            txnHelper.doInTransaction(new RetryingTransactionCallback<Object>()
            {
                public Object execute() throws Throwable
                {
                    makeHomeFolderAsSystem(ref);
                    return null;
                }
            }, false, requiresNew);
        }
    }
}
 
Example 30
/**
 * Make an ETag value for a node using the GUID and modify date/time
 */
protected final void makeETagString(FileInfo nodeInfo, StringBuilder etag)
{
    // Get the modify date/time property for the node
    
    Object modVal = nodeInfo.getProperties().get(ContentModel.PROP_MODIFIED);
    
    etag.append(nodeInfo.getNodeRef().getId());
    
    if ( modVal != null)
    {
        etag.append("_");
        etag.append(DefaultTypeConverter.INSTANCE.longValue(modVal));
    }
}