Search in sources :

Example 1 with Tag

use of com.day.cq.tagging.Tag in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class PageImpl method initModel.

@PostConstruct
private void initModel() {
    title = currentPage.getTitle();
    if (StringUtils.isBlank(title)) {
        title = currentPage.getName();
    }
    Tag[] tags = currentPage.getTags();
    keywords = new String[tags.length];
    int index = 0;
    for (Tag tag : tags) {
        keywords[index++] = tag.getTitle(currentPage.getLanguage(false));
    }
    if (currentDesign != null) {
        String designPath = currentDesign.getPath();
        if (!Designer.DEFAULT_DESIGN_PATH.equals(designPath)) {
            this.designPath = designPath;
            if (resolver.getResource(designPath + "/static.css") != null) {
                staticDesignPath = designPath + "/static.css";
            }
            loadFavicons(designPath);
        }
    }
    populateClientLibCategories();
    templateName = extractTemplateName();
}
Also used : Tag(com.day.cq.tagging.Tag) PostConstruct(javax.annotation.PostConstruct)

Example 2 with Tag

use of com.day.cq.tagging.Tag in project acs-aem-commons by Adobe-Consulting-Services.

the class PropertyMergePostProcessorTest method testMergeAllTags.

@Test
public void testMergeAllTags() throws Exception {
    final TagManager mockTagManager = mock(TagManager.class);
    Tag fakeTag = mock(Tag.class);
    when(mockTagManager.resolve(any())).thenReturn(fakeTag);
    context.registerAdapter(ResourceResolver.class, TagManager.class, mockTagManager);
    ResourceResolver rr = context.resourceResolver();
    MockSlingHttpServletRequest request = context.request();
    request.setParameterMap(new HashMap<String, Object>() {

        {
            put("./asset/jcr:content/metadata/dam:tag1", new String[] { "tag1:tag1a", "tag1:tag1b" });
            put("./asset/jcr:content/metadata/dam:tag2", new String[] { "tag2:tag2a", "tag2:tag2b" });
            put(":" + PropertyMergePostProcessor.OPERATION_ALL_TAGS + "@PropertyMerge", "jcr:content/metadata/dam:combined-tags");
        }
    });
    Map<String, Object> emptyProperties = new HashMap<>();
    Resource content = rr.create(rr.resolve("/"), "content", emptyProperties);
    Resource dam = rr.create(content, "dam", emptyProperties);
    request.setResource(dam);
    Resource asset = rr.create(dam, "asset", emptyProperties);
    Resource jcrContent = rr.create(asset, "jcr:content", emptyProperties);
    Resource metadata = rr.create(jcrContent, "metadata", new HashMap<String, Object>() {

        {
            put("dam:tag1", new String[] { "tag1:tag1a", "tag1:tag1b" });
            put("dam:tag2", new String[] { "tag2:tag2a", "tag2:tag2b" });
        }
    });
    PropertyMergePostProcessor processor = new PropertyMergePostProcessor();
    List<Modification> changeLog = new ArrayList<>();
    processor.process(request, changeLog);
    Assert.assertFalse("Should have observed some changes", changeLog.isEmpty());
    String[] tags = metadata.getValueMap().get("dam:combined-tags", String[].class);
    Assert.assertArrayEquals(new String[] { "tag1:tag1a", "tag1:tag1b", "tag2:tag2a", "tag2:tag2b" }, tags);
}
Also used : Modification(org.apache.sling.servlets.post.Modification) HashMap(java.util.HashMap) Resource(org.apache.sling.api.resource.Resource) ArrayList(java.util.ArrayList) TagManager(com.day.cq.tagging.TagManager) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Tag(com.day.cq.tagging.Tag) Test(org.junit.Test)

Example 3 with Tag

use of com.day.cq.tagging.Tag in project acs-aem-commons by Adobe-Consulting-Services.

the class TagCreator method createTag.

private void createTag(TagDefinition tagDefinition, TagManager tagManager) {
    ReportRowSatus status;
    try {
        if (tagManager.resolve(tagDefinition.getId()) == null) {
            status = ReportRowSatus.CREATED;
        } else {
            status = ReportRowSatus.UPDATED_EXISTING;
        }
        final Tag tag = tagManager.createTag(tagDefinition.getId(), tagDefinition.getTitle(), tagDefinition.getDescription(), false);
        if (tag != null) {
            setTitles(tag, tagDefinition);
            record(status, tag.getTagID(), tag.getPath(), tag.getTitle());
            log.debug("Created tag [ {} -> {} ]", tagDefinition.getId(), tagDefinition.getTitle());
        } else {
            log.error("Tag [ {} ] is null", tagDefinition.getId());
        }
    } catch (Exception e) {
        record(ReportRowSatus.FAILED_TO_CREATE, tagDefinition.getId(), tagDefinition.getPath(), tagDefinition.getTitle());
        log.error("Unable to create tag [ {} -> {} ]", tagDefinition.getId(), tagDefinition.getTitle());
    }
}
Also used : Tag(com.day.cq.tagging.Tag) RepositoryException(javax.jcr.RepositoryException) PersistenceException(org.apache.sling.api.resource.PersistenceException) IOException(java.io.IOException) LoginException(org.apache.sling.api.resource.LoginException)

Example 4 with Tag

use of com.day.cq.tagging.Tag in project acs-aem-commons by Adobe-Consulting-Services.

the class TagsCellValue method getTags.

public List<Tag> getTags() {
    TagManager tagMgr = request.getResourceResolver().adaptTo(TagManager.class);
    Resource resource = (Resource) request.getAttribute("result");
    log.debug("Loading tags from {}@{}", new String[] { resource.getPath(), property });
    List<Tag> tags = new ArrayList<Tag>();
    String[] values = resource.getValueMap().get(property, String[].class);
    if (values != null) {
        for (String value : values) {
            tags.add(tagMgr.resolve(value));
        }
    }
    log.debug("Loaded {} tags", tags.size());
    return tags;
}
Also used : TagManager(com.day.cq.tagging.TagManager) Resource(org.apache.sling.api.resource.Resource) ArrayList(java.util.ArrayList) Tag(com.day.cq.tagging.Tag)

Example 5 with Tag

use of com.day.cq.tagging.Tag in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class PageImpl method initModel.

@PostConstruct
protected void initModel() {
    title = currentPage.getTitle();
    description = currentPage.getDescription();
    if (StringUtils.isBlank(title)) {
        title = currentPage.getName();
    }
    Tag[] tags = currentPage.getTags();
    keywords = new String[tags.length];
    int index = 0;
    for (Tag tag : tags) {
        keywords[index++] = tag.getTitle(currentPage.getLanguage(false));
    }
    if (currentDesign != null) {
        String designPath = currentDesign.getPath();
        if (!Designer.DEFAULT_DESIGN_PATH.equals(designPath)) {
            this.designPath = designPath;
            if (resolver.getResource(designPath + "/static.css") != null) {
                staticDesignPath = designPath + "/static.css";
            }
            loadFavicons(designPath);
        }
    }
    populateClientlibCategories();
    templateName = extractTemplateName();
    brandSlug = Utils.getInheritedValue(currentPage, PN_BRANDSLUG);
}
Also used : Tag(com.day.cq.tagging.Tag) PostConstruct(javax.annotation.PostConstruct)

Aggregations

Tag (com.day.cq.tagging.Tag)5 TagManager (com.day.cq.tagging.TagManager)2 ArrayList (java.util.ArrayList)2 PostConstruct (javax.annotation.PostConstruct)2 Resource (org.apache.sling.api.resource.Resource)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 RepositoryException (javax.jcr.RepositoryException)1 LoginException (org.apache.sling.api.resource.LoginException)1 PersistenceException (org.apache.sling.api.resource.PersistenceException)1 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)1 Modification (org.apache.sling.servlets.post.Modification)1 MockSlingHttpServletRequest (org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest)1 Test (org.junit.Test)1