Search in sources :

Example 51 with Category

use of com.agiletec.aps.system.services.category.Category in project entando-core by entando.

the class IndexerDAO method createDocument.

/**
 * Crea un oggetto Document pronto per l'indicizzazione da un oggetto
 * Content.
 *
 * @param entity Il dataobject dal quale ricavare il Document.
 * @return L'oggetto Document ricavato dal dataobject.
 * @throws ApsSystemException In caso di errore
 */
protected Document createDocument(IApsEntity entity) throws ApsSystemException {
    Document document = new Document();
    document.add(new StringField(DATAOBJECT_ID_FIELD_NAME, entity.getId(), Field.Store.YES));
    document.add(new TextField(DATAOBJECT_TYPE_FIELD_NAME, entity.getTypeCode(), Field.Store.YES));
    document.add(new StringField(DATAOBJECT_GROUP_FIELD_NAME, entity.getMainGroup(), Field.Store.YES));
    Iterator<String> iterGroups = entity.getGroups().iterator();
    while (iterGroups.hasNext()) {
        String groupName = (String) iterGroups.next();
        document.add(new StringField(DATAOBJECT_GROUP_FIELD_NAME, groupName, Field.Store.YES));
    }
    try {
        EntityAttributeIterator attributesIter = new EntityAttributeIterator(entity);
        while (attributesIter.hasNext()) {
            AttributeInterface currentAttribute = (AttributeInterface) attributesIter.next();
            List<Lang> langs = this.getLangManager().getLangs();
            for (int i = 0; i < langs.size(); i++) {
                Lang currentLang = (Lang) langs.get(i);
                this.indexAttribute(document, currentAttribute, currentLang);
            }
        }
        List<Category> categories = entity.getCategories();
        if (null != categories && !categories.isEmpty()) {
            for (int i = 0; i < categories.size(); i++) {
                Category category = categories.get(i);
                this.indexCategory(document, category);
            }
        }
    } catch (Throwable t) {
        _logger.error("Error creating document", t);
        throw new ApsSystemException("Error creating document", t);
    }
    return document;
}
Also used : Category(com.agiletec.aps.system.services.category.Category) Lang(com.agiletec.aps.system.services.lang.Lang) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) Document(org.apache.lucene.document.Document) StringField(org.apache.lucene.document.StringField) TextField(org.apache.lucene.document.TextField) IndexableAttributeInterface(com.agiletec.aps.system.common.searchengine.IndexableAttributeInterface) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) EntityAttributeIterator(com.agiletec.aps.system.common.util.EntityAttributeIterator)

Example 52 with Category

use of com.agiletec.aps.system.services.category.Category in project entando-core by entando.

the class TestSearchEngineManager method testSearchContentsId_5.

public void testSearchContentsId_5() throws Throwable {
    try {
        Thread thread = this.dataObjectSearchEngineManager.startReloadDataObjectsReferences();
        thread.join();
        SearchEngineManager sem = (SearchEngineManager) this.dataObjectSearchEngineManager;
        Category general_cat2 = this._categoryManager.getCategory("general_cat2");
        List<ITreeNode> categories = new ArrayList<ITreeNode>();
        categories.add(general_cat2);
        List<String> allowedGroup = new ArrayList<String>();
        allowedGroup.add(Group.FREE_GROUP_NAME);
        List<String> contentsId = sem.searchEntityId(null, categories, allowedGroup);
        assertNotNull(contentsId);
        assertTrue(contentsId.isEmpty());
        allowedGroup.add(Group.ADMINS_GROUP_NAME);
        contentsId = sem.searchEntityId(null, categories, allowedGroup);
        String[] expected1 = { "ART111", "ART120" };
        this.verify(contentsId, expected1);
        Category general_cat1 = this._categoryManager.getCategory("general_cat1");
        categories.add(general_cat1);
        contentsId = sem.searchEntityId(null, categories, allowedGroup);
        assertNotNull(contentsId);
        String[] expected2 = { "ART111" };
        this.verify(contentsId, expected2);
    } catch (Throwable t) {
        throw t;
    }
}
Also used : Category(com.agiletec.aps.system.services.category.Category) ITreeNode(com.agiletec.aps.system.common.tree.ITreeNode) IDataObjectSearchEngineManager(org.entando.entando.aps.system.services.dataobjectsearchengine.IDataObjectSearchEngineManager) SearchEngineManager(org.entando.entando.aps.system.services.dataobjectsearchengine.SearchEngineManager) ArrayList(java.util.ArrayList)

Example 53 with Category

use of com.agiletec.aps.system.services.category.Category in project entando-core by entando.

the class TestSearchEngineManager method createDataObject_2.

private DataObject createDataObject_2() {
    DataObject content = new DataObject();
    content.setId("101");
    content.setMainGroup(Group.FREE_GROUP_NAME);
    content.addGroup("thirdGroup");
    content.setTypeCode("ART");
    TextAttribute text = new TextAttribute();
    text.setName("Articolo");
    text.setType("Text");
    text.setIndexingType(IndexableAttributeInterface.INDEXING_TYPE_TEXT);
    text.setText("Il turismo ha incrementato più del 20 per cento nel 2011-2013, quando la Croazia ha aderito all'Unione europea. Consegienda di questo aumento è una serie di modernizzazione di alloggi di recente costruzione, tra cui circa tre dozzine di ostelli.", "it");
    text.setText("Tourism had shot up more than 20 percent from 2011 to 2013, when Croatia joined the European Union. Accompanying that rise is a raft of modernized and recently built lodgings, including some three dozen hostels.", "en");
    content.addAttribute(text);
    Category category1 = this._categoryManager.getCategory("resCat1");
    Category category2 = this._categoryManager.getCategory("general_cat2");
    content.addCategory(category1);
    content.addCategory(category2);
    return content;
}
Also used : DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject) Category(com.agiletec.aps.system.services.category.Category) TextAttribute(com.agiletec.aps.system.common.entity.model.attribute.TextAttribute)

Example 54 with Category

use of com.agiletec.aps.system.services.category.Category in project entando-core by entando.

the class TestSearchEngineManager method createDataObject_3.

private DataObject createDataObject_3() {
    DataObject content = new DataObject();
    content.setId("103");
    content.setMainGroup(Group.FREE_GROUP_NAME);
    content.setTypeCode("ART");
    TextAttribute text = new TextAttribute();
    text.setName("Articolo");
    text.setType("Text");
    text.setIndexingType(IndexableAttributeInterface.INDEXING_TYPE_TEXT);
    text.setText("La vita è una cosa meravigliosa", "it");
    text.setText("Life is a wonderful thing", "en");
    content.addAttribute(text);
    Category category = this._categoryManager.getCategory("general_cat1");
    content.addCategory(category);
    return content;
}
Also used : DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject) Category(com.agiletec.aps.system.services.category.Category) TextAttribute(com.agiletec.aps.system.common.entity.model.attribute.TextAttribute)

Example 55 with Category

use of com.agiletec.aps.system.services.category.Category in project entando-core by entando.

the class ResourceManagerIntegrationTest method testUpdateResource.

public void testUpdateResource() throws Throwable {
    String oldDescr = null;
    List<Category> oldCategories = null;
    try {
        ResourceInterface resource = this._resourceManager.loadResource("44");
        assertTrue(resource instanceof ImageResource);
        assertEquals(resource.getDescription(), "logo");
        assertEquals(resource.getCategories().size(), 1);
        assertTrue(resource.isMultiInstance());
        oldCategories = resource.getCategories();
        oldDescr = resource.getDescription();
        String newDescr = "New Description";
        resource.setDescription(newDescr);
        resource.setCategories(new ArrayList<Category>());
        this._resourceManager.updateResource(resource);
        resource = this._resourceManager.loadResource("44");
        assertEquals(resource.getDescription(), newDescr);
        assertEquals(resource.getCategories().size(), 0);
    } catch (Throwable t) {
        throw t;
    } finally {
        if (oldCategories != null && oldDescr != null) {
            ResourceInterface resource = this._resourceManager.loadResource("44");
            resource.setCategories(oldCategories);
            resource.setDescription(oldDescr);
            this._resourceManager.updateResource(resource);
        }
    }
}
Also used : Category(com.agiletec.aps.system.services.category.Category) ImageResource(com.agiletec.plugins.jacms.aps.system.services.resource.model.ImageResource) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)

Aggregations

Category (com.agiletec.aps.system.services.category.Category)85 ArrayList (java.util.ArrayList)21 ITreeNode (com.agiletec.aps.system.common.tree.ITreeNode)9 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)7 TextAttribute (com.agiletec.aps.system.common.entity.model.attribute.TextAttribute)6 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)6 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)5 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)5 RestServerError (org.entando.entando.aps.system.exception.RestServerError)5 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)4 ICategoryManager (com.agiletec.aps.system.services.category.ICategoryManager)4 Lang (com.agiletec.aps.system.services.lang.Lang)4 ResourceInterface (com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)4 List (java.util.List)4 CategoryDto (org.entando.entando.aps.system.services.category.model.CategoryDto)4 IDataObjectSearchEngineManager (org.entando.entando.aps.system.services.dataobjectsearchengine.IDataObjectSearchEngineManager)4 SearchEngineManager (org.entando.entando.aps.system.services.dataobjectsearchengine.SearchEngineManager)4 CategoryUtilizer (com.agiletec.aps.system.services.category.CategoryUtilizer)3 HashSet (java.util.HashSet)3 DataObject (org.entando.entando.aps.system.services.dataobject.model.DataObject)3