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

The following examples show how to use org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter. 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
Source File: AuthorityNameConstraint.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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
Source File: OwnableServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 #3
Source File: ObjectIdLuceneBuilder.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 #4
Source File: TikaAudioMetadataExtracterTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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 #5
Source File: AuthorityDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 #6
Source File: NodePropertyValue.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 #7
Source File: GetPeopleCannedQueryTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 #8
Source File: StringLengthConstraint.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 #9
Source File: RenditionService2Impl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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 #10
Source File: DWGMetadataExtracterTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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 #11
Source File: NumericRangeConstraint.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
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
Source File: AbstractProperty.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 #13
Source File: RepositoryAuthenticationDao.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 #14
Source File: RepositoryAuthenticationDao.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @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 #15
Source File: MultilingualContentServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 #16
Source File: HtmlMetadataExtracterTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 #17
Source File: LuceneExists.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 #18
Source File: RenditionService2IntegrationTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 #19
Source File: UserNameConstraint.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 #20
Source File: TikaAudioMetadataExtracterTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/** 
* Tests for various Audio specific bits of metadata 
*/
public void testFileSpecificMetadata(String mimetype, Map<QName, Serializable> properties) {
   QName album = QName.createQName(NamespaceService.AUDIO_MODEL_1_0_URI, "album");
   assertEquals(
         "Property " + album + " not found for mimetype " + mimetype,
         ALBUM,
         DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(album)));
   
   QName artist = QName.createQName(NamespaceService.AUDIO_MODEL_1_0_URI, "artist");
   assertEquals(
         "Property " + artist + " not found for mimetype " + mimetype,
         ARTIST,
         DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(artist)));
   
   QName genre = QName.createQName(NamespaceService.AUDIO_MODEL_1_0_URI, "genre");
   assertEquals(
         "Property " + genre + " not found for mimetype " + mimetype,
         GENRE,
         DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(genre)));

   QName releaseDate = QName.createQName(NamespaceService.AUDIO_MODEL_1_0_URI, "releaseDate");
   assertEquals(
         "Property " + releaseDate + " not found for mimetype " + mimetype,
         "2009-01-01T00:00:00.000Z",
         DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(releaseDate)));

   QName channels = QName.createQName(NamespaceService.AUDIO_MODEL_1_0_URI, "channelType");
   assertEquals(
         "Property " + channels + " not found for mimetype " + mimetype,
         "Stereo",
         DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(channels)));

   
   // Description is a composite - check the artist part
   assertContains(
         "Property " + ContentModel.PROP_DESCRIPTION + " didn't contain " +  ARTIST + " for mimetype " + mimetype,
         ARTIST,
         DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_DESCRIPTION)));
}
 
Example #21
Source File: TestCustomConstraint.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void evaluateSingleValue(Object value)
{
    String checkValue = DefaultTypeConverter.INSTANCE.convert(String.class, value);

    if (checkValue.contains("#"))
    {
        throw new ConstraintException("The value must not contain '#'");
    }
}
 
Example #22
Source File: AuditablePropertiesEntity.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * For internal use.  Provides access to the time (<tt>long</tt>) for the
 * {@link #getAuditModified() auditModified} property.
 */
private long getAuditModifiedTime()
{
    if (auditModifiedTime < 0 && auditModified != null)
    {
        auditModifiedTime = DefaultTypeConverter.INSTANCE.convert(Date.class, auditModified).getTime();
    }
    return auditModifiedTime;
}
 
Example #23
Source File: AbstractLocaleDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Find the locale pair
 * 
 * @param locale                the locale to get or <tt>null</tt> to indicate the
 *                              {@link LocaleEntity#DEFAULT_LOCALE_SUBSTITUTE default locale}.
 * @return                      Returns the locale pair (ID, Locale) or <tt>null</tt> if not found.
 */
private Pair<Long, Locale> getLocalePairImpl(Locale locale)
{
    // Null means look for the default
    final String localeStr;
    if (locale == null)
    {
        localeStr = LocaleEntity.DEFAULT_LOCALE_SUBSTITUTE;
        locale = I18NUtil.getLocale();
    }
    else
    {
        localeStr = DefaultTypeConverter.INSTANCE.convert(String.class, locale);
    }
    
    if (localeStr == null)
    {
        throw new IllegalArgumentException("Cannot look up entity by null locale.");
    }
    
    Pair<Long, String> entityPair = localeEntityCache.getByValue(localeStr);
    if (entityPair == null)
    {
        return null;
    }
    else
    {
        return new Pair<Long, Locale>(entityPair.getFirst(), locale);
    }
}
 
Example #24
Source File: ReferenceablePropertiesEntity.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Remove all {@link ContentModel#ASPECT_REFERENCEABLE referencable} properties
 */
public static void removeReferenceableProperties(Node node, Map<QName, Serializable> properties)
{
    properties.keySet().removeAll(REFERENCEABLE_PROP_QNAMES);
    String name = DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_NAME));
    if (name != null && name.equals(node.getUuid()))
    {
        // The cm:name matches the UUID, so drop it
        properties.remove(ContentModel.PROP_NAME);
    }
}
 
Example #25
Source File: AbstractLocaleDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Find or create the locale pair
 * 
 * @param locale                the locale to get or <tt>null</tt> to indicate the
 *                              {@link LocaleEntity#DEFAULT_LOCALE_SUBSTITUTE default locale}.
 * @return                      Returns the locale pair (ID, Locale), never <tt>null
 */
private Pair<Long, Locale> getOrCreateLocalePairImpl(Locale locale)
{
    // Null means look for the default
    final String localeStr;
    if (locale == null)
    {
        localeStr = LocaleEntity.DEFAULT_LOCALE_SUBSTITUTE;
        locale = I18NUtil.getLocale();
    }
    else
    {
        localeStr = DefaultTypeConverter.INSTANCE.convert(String.class, locale);
    }
    
    if (localeStr == null)
    {
        throw new IllegalArgumentException("Cannot look up entity by null locale.");
    }
    
    Pair<Long, String> entityPair = localeEntityCache.getOrCreateByValue(localeStr);
    if (entityPair == null)
    {
        throw new RuntimeException("Locale should have been created.");
    }
    return new Pair<Long, Locale>(entityPair.getFirst(), locale);
}
 
Example #26
Source File: RFC822MetadataExtracterTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * We have no author, and have the same title and description
 */
protected void testCommonMetadata(String mimetype,
     Map<QName, Serializable> properties) {
   assertEquals(
         "Property " + ContentModel.PROP_TITLE + " not found for mimetype " + mimetype,
         QUICK_TITLE,
         DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_TITLE)));
   assertEquals(
         "Property " + ContentModel.PROP_DESCRIPTION + " not found for mimetype " + mimetype,
         QUICK_TITLE,
         DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_DESCRIPTION)));
}
 
Example #27
Source File: ArchiveFileContentStore.java    From alfresco-simple-content-stores with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void onUpdateProperties(final NodeRef nodeRef, final Map<QName, Serializable> before, final Map<QName, Serializable> after)
{
    // no need to check if retentionDatePropertyQName or retentionViaAccessTime are actually set
    // behaviour would not have been registered if that wasn't the case

    final Serializable retentionBefore = before.get(this.retentionDatePropertyQName);
    final Serializable retentionAfter = after.get(this.retentionDatePropertyQName);

    if (!EqualsHelper.nullSafeEquals(retentionBefore, retentionAfter))
    {
        LOGGER.debug("Handling update of retention target {} on {} from {} to {}", this.retentionDatePropertyQName, nodeRef,
                retentionBefore, retentionAfter);
        final Date retentionTargetDate = DefaultTypeConverter.INSTANCE.convert(Date.class, retentionAfter);
        if (retentionTargetDate != null)
        {
            final Map<QName, Serializable> properties = this.nodeService.getProperties(nodeRef);

            final List<QName> contentPropertyQNames = properties.keySet().stream().map(this.dictionaryService::getProperty)
                    .filter(p -> p != null).filter(p -> DataTypeDefinition.CONTENT.equals(p.getDataType().getName()))
                    .map(PropertyDefinition::getName).collect(Collectors.toList());
            LOGGER.debug("Identified {} as d:content properties to process on {}", contentPropertyQNames, nodeRef);

            contentPropertyQNames.stream().map(properties::get)
                    .forEach(pv -> this.processContentPropertyForRetentionUpdate(pv, retentionTargetDate, retentionBefore == null));
        }
        else
        {
            LOGGER.warn("Unable to update retention on any content of {} as node no longer has a value for {}", nodeRef,
                    this.retentionDatePropertyQName);
        }
    }
}
 
Example #28
Source File: XMLTransferManifestWriter.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void writeMLValue(Locale locale, Serializable value) throws SAXException
{
    AttributesImpl attributes = new AttributesImpl();
    attributes.addAttribute(TransferModel.TRANSFER_MODEL_1_0_URI, "locale", "locale", "String",
                locale.toString());
    writer.startElement(TransferModel.TRANSFER_MODEL_1_0_URI,
                ManifestModel.LOCALNAME_ELEMENT_MLVALUE, PREFIX + ":"
                            + ManifestModel.LOCALNAME_ELEMENT_MLVALUE, attributes);
    if (value != null)
    {
        String strValue = (String) DefaultTypeConverter.INSTANCE.convert(String.class, value);
        
        boolean oldValue = format.isTrimText();
        format.setTrimText(false);
        try
        {
           writer.characters(strValue.toCharArray(), 0, strValue.length());
        }
        finally
        {
           format.setTrimText(oldValue);
        }
    }
    writer.endElement(TransferModel.TRANSFER_MODEL_1_0_URI,
                ManifestModel.LOCALNAME_ELEMENT_MLVALUE, PREFIX + ":"
                            + ManifestModel.LOCALNAME_ELEMENT_MLVALUE);
}
 
Example #29
Source File: Upper.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Serializable getValue(Map<String, Argument> args, FunctionEvaluationContext context)
{
    Argument arg = args.get(ARG_ARG);
    Serializable value = arg.getValue(context);
    String stringValue = DefaultTypeConverter.INSTANCE.convert(String.class, value);
    return stringValue.toUpperCase();
}
 
Example #30
Source File: Lower.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Serializable getValue(Map<String, Argument> args, FunctionEvaluationContext context)
{
    Argument arg = args.get(ARG_ARG);
    Serializable value = arg.getValue(context);
    String stringValue = DefaultTypeConverter.INSTANCE.convert(String.class, value);
    return stringValue.toLowerCase();
}