4

I have added the following custom aspect to my content model:

<aspect name="my:locationDocumentClassification">
    <title>My Location Document Classification</title>
    <parent>cm:classifiable</parent>
    <properties>
        <property name="my:locationDocumentCategory">
            <title>Location Document Categories</title>
            <type>d:category</type>
            <mandatory>false</mandatory>
            <multiple>false</multiple>
            <index enabled="true">
                <atomic>true</atomic>
                <stored>true</stored>
                <tokenised>false</tokenised>
            </index>
        </property> 
    </properties>
</aspect>

Now I want to be able to populate a set of categories to the classification. I am using the following Webscript to populate the categories:

    protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
//        NodeRef newRootCat = categoryService.createRootCategory(
//                StoreRef.STORE_REF_WORKSPACE_SPACESSTORE,
//                ContentModel.ASPECT_GEN_CLASSIFIABLE,
//                "testroot");
//        LOGGER.log(Level.INFO, "Created: {0}", newRootCat.toString());
//        NodeRef newCategory = categoryService.createCategory(newRootCat, "testcat");
//        LOGGER.log(Level.INFO, "Created: {0}", newCategory.toString());
//        NodeRef locationDocumentClassification = categoryService.createClassification(
//                StoreRef.STORE_REF_WORKSPACE_SPACESSTORE,
//                MyModel.ASPECT_MY_LOCATION_DOCUMENT_CLASSIFICATION, 
//                "locationDocumentClassification");
//        LOGGER.log(Level.INFO, "Created: {0}", locationDocumentClassification.toString());
        NodeRef locationDocumentRootCat = categoryService.createRootCategory(
                StoreRef.STORE_REF_WORKSPACE_SPACESSTORE,
                MyModel.ASPECT_MY_LOCATION_DOCUMENT_CLASSIFICATION,
                "testroot");
        LOGGER.log(Level.INFO, "Created: {0}", locationDocumentRootCat.toString());
        NodeRef klantDocCat = categoryService.createCategory(locationDocumentRootCat, "testcat");
        LOGGER.log(Level.INFO, "Created: {0}", klantDocCat.toString());
        return new HashMap<>();
    }

When I execute the code, I get the following error:

10170041 Wrapped Exception (with status template): 10170014 Missing classification: {http://my.company.com/model/content/1.0}locationDocumentClassification

The first two commented out statements in the code is the example code from Alfresco, which works fine. The third commented out statement is me trying to create a classification first to see if that works. The error that I get when I uncomment the createClassification statement:

java.lang.UnsupportedOperationException         at org.alfresco.repo.search.impl.lucene.LuceneCategoryServiceImpl.createClassification(LuceneCategoryServiceImpl.java:369)

So no luck there. I hope there is anyone out there who can see the problem. I read all the posts and forums I could find about this, but could not figure out an answer.

I am using Alfresco 5.0d community edition.

Martijn Burger
  • 7,315
  • 8
  • 54
  • 94
  • Cross posted on the Alfresco forum: https://forums.alfresco.com/forum/developer-discussions/content-modeling/cannot-create-custom-classification-11192015-1614 – Martijn Burger Nov 23 '15 at 08:44

1 Answers1

0

If you download the source files of the SDK you'll see that you're firing the following code:

public NodeRef createRootCategory(StoreRef storeRef, QName aspectName, String name)
    {
        Set<NodeRef> nodeRefs = getClassificationNodes(storeRef, aspectName);
        if (nodeRefs.size() == 0)
        {
            throw new AlfrescoRuntimeException("Missing classification: " + aspectName);
        }
        NodeRef parent = nodeRefs.iterator().next();
        return createCategory(parent, name);
    }



private Set<NodeRef> getClassificationNodes(StoreRef storeRef, QName qname)
    {
        ResultSet resultSet = null;
        try
        {
            resultSet = indexerAndSearcher.getSearcher(storeRef, false).query(storeRef, "lucene",
                    "PATH:\"/" + getPrefix(qname.getNamespaceURI()) + ISO9075.encode(qname.getLocalName()) + "\"", null);

            etc....
    }

So basically what it's trying to do is search for already created categories and create a root.

So what you need to do is just use the code to create a node of type cm:category in the category_root and add your aspect to it. Do a search on TYPE:"cm:category_root" and create it.

Or create your own type which has parent of cm:category. The only issue with this is that you'll need to change a lot of UI elements, cause they only check on type cm:category.

Tahir Malik
  • 6,623
  • 15
  • 22
  • Hi Tarik, thanks for your answer. As you can see in the model snippet I posted I am creating my own category named `my:locationDocumentCategory` instead of using `cm:category`. That's why I am trying to create a new root_category. What do you mean with it needs to be a parent of `cm:category` when you use your own type? The structure I am using is exactly the same as the default category model. – Martijn Burger Nov 26 '15 at 14:11
  • Hi Martijn, It's Tahir. You are not creating your own category type. You are creating an aspect which is different. Is you check in the nodebrowser on a category, you'll see that the type of the category is cm:category and the aspect applied is cm:generalclassifiable. So what You did is only the second part which is creating a custom aspect. You'll need to create a custom type as well. It's nit compulsory to create a custom type like I said. The aspect is sufficient in many cases. – Tahir Malik Nov 27 '15 at 07:43
  • Sorry, Tahir. Thanks for the infromation. I want three classifications for different document types, so I guess I really need the custom type. Thanks! – Martijn Burger Nov 27 '15 at 09:00