Search in sources :

Example 26 with Category

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

the class CategoryControllerIntegrationTest method testUpdateCategory.

@Test
public void testUpdateCategory() throws Exception {
    String categoryCode = "test_cat2";
    try {
        Assert.assertNotNull(this.categoryManager.getCategory("cat1"));
        Assert.assertNull(this.categoryManager.getCategory(categoryCode));
        UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
        String accessToken = mockOAuthInterceptor(user);
        ResultActions result = this.executePost("2_POST_valid.json", accessToken, status().isOk());
        result.andExpect(jsonPath("$.errors", Matchers.hasSize(0)));
        result.andExpect(jsonPath("$.payload.code", is(categoryCode)));
        result = this.executePut("2_PUT_invalid_1.json", categoryCode, accessToken, status().isBadRequest());
        result.andExpect(jsonPath("$.payload", Matchers.hasSize(0)));
        result.andExpect(jsonPath("$.errors[0].code", is(CategoryValidator.ERRCODE_PARENT_CATEGORY_CANNOT_BE_CHANGED)));
        result = this.executePut("2_PUT_invalid_2.json", categoryCode, accessToken, status().isBadRequest());
        result.andExpect(jsonPath("$.payload", Matchers.hasSize(0)));
        result.andExpect(jsonPath("$.errors[0].code", is("53")));
        result = this.executePut("2_PUT_valid.json", "home", accessToken, status().isBadRequest());
        result.andExpect(jsonPath("$.payload", Matchers.hasSize(0)));
        result.andExpect(jsonPath("$.errors[0].code", is(CategoryValidator.ERRCODE_URINAME_MISMATCH)));
        result = this.executePut("2_PUT_valid.json", categoryCode, accessToken, status().isOk());
        result.andExpect(jsonPath("$.errors", Matchers.hasSize(0)));
        result.andExpect(jsonPath("$.payload.code", is(categoryCode)));
        Category modified = this.categoryManager.getCategory(categoryCode);
        Assert.assertNotNull(modified);
        Assert.assertTrue(modified.getTitle("en").startsWith("New "));
        Assert.assertTrue(modified.getTitle("it").startsWith("Nuovo "));
        result = this.executeDelete(categoryCode, accessToken, status().isOk());
        result.andExpect(jsonPath("$.payload.code", is(categoryCode)));
        result.andExpect(jsonPath("$.errors", Matchers.hasSize(0)));
        Assert.assertNull(this.categoryManager.getCategory(categoryCode));
    } finally {
        if (categoryManager.getCategory(categoryCode) != null) {
            this.categoryManager.deleteCategory(categoryCode);
        }
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) Category(com.agiletec.aps.system.services.category.Category) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 27 with Category

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

the class TestSearchEngineManager method testSearchFacetedContents_1.

public void testSearchFacetedContents_1() throws Throwable {
    try {
        Thread thread = this.dataObjectSearchEngineManager.startReloadDataObjectsReferences();
        thread.join();
        SearchEngineManager sem = (SearchEngineManager) this.dataObjectSearchEngineManager;
        Category general = this._categoryManager.getCategory("general");
        List<ITreeNode> categories = new ArrayList<ITreeNode>();
        categories.add(general);
        List<String> allowedGroup = new ArrayList<String>();
        allowedGroup.add(Group.FREE_GROUP_NAME);
        allowedGroup.add(Group.ADMINS_GROUP_NAME);
        FacetedContentsResult result = sem.searchFacetedEntities(null, categories, allowedGroup);
        assertNotNull(result);
        String[] expected1 = { "ART122", "ART102", "ART111", "ART120" };
        this.verify(result.getContentsId(), expected1);
        assertEquals(4, result.getOccurrences().size());
    } catch (Throwable t) {
        throw t;
    }
}
Also used : FacetedContentsResult(org.entando.entando.aps.system.services.searchengine.FacetedContentsResult) 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 28 with Category

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

the class TestSearchEngineManager method createDataObject_1.

private DataObject createDataObject_1() {
    DataObject content = new DataObject();
    content.setId("100");
    content.setMainGroup(Group.FREE_GROUP_NAME);
    content.addGroup("secondaryGroup");
    content.setTypeCode("ART");
    TextAttribute text = new TextAttribute();
    text.setName("Articolo");
    text.setType("Text");
    text.setIndexingType(IndexableAttributeInterface.INDEXING_TYPE_TEXT);
    text.setText("San Pietroburgo è una città meravigliosa W3C-WAI", "it");
    text.setText("St. Petersburg is a wonderful city", "en");
    content.addAttribute(text);
    Category category1 = this._categoryManager.getCategory("resCat2");
    Category category2 = this._categoryManager.getCategory("general_cat3");
    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 29 with Category

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

the class TestSearchEngineManager method testSearchContentsId_4.

public void testSearchContentsId_4() throws Throwable {
    try {
        Thread thread = this.dataObjectSearchEngineManager.startReloadDataObjectsReferences();
        thread.join();
        SearchEngineManager sem = (SearchEngineManager) this.dataObjectSearchEngineManager;
        SearchEngineFilter filterByType = new SearchEngineFilter(IIndexerDAO.DATAOBJECT_TYPE_FIELD_NAME, "ART");
        SearchEngineFilter[] filters = { filterByType };
        List<String> allowedGroup = new ArrayList<String>();
        allowedGroup.add(Group.FREE_GROUP_NAME);
        List<String> contentsId = sem.searchEntityId(filters, null, allowedGroup);
        assertNotNull(contentsId);
        String[] expected1 = { "ART180", "ART1", "ART187", "ART121" };
        this.verify(contentsId, expected1);
        Category cat1 = this._categoryManager.getCategory("cat1");
        List<ITreeNode> categories = new ArrayList<ITreeNode>();
        categories.add(cat1);
        contentsId = sem.searchEntityId(filters, categories, allowedGroup);
        assertNotNull(contentsId);
        String[] expected2 = { "ART180" };
        this.verify(contentsId, expected2);
    } catch (Throwable t) {
        throw t;
    }
}
Also used : SearchEngineFilter(org.entando.entando.aps.system.services.searchengine.SearchEngineFilter) 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 30 with Category

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

the class TestSearchEngineManager method testSearchContentsId_6.

public void testSearchContentsId_6() throws Throwable {
    try {
        Thread thread = this.dataObjectSearchEngineManager.startReloadDataObjectsReferences();
        thread.join();
        SearchEngineManager sem = (SearchEngineManager) this.dataObjectSearchEngineManager;
        Category general = this._categoryManager.getCategory("general");
        List<ITreeNode> categories = new ArrayList<ITreeNode>();
        categories.add(general);
        List<String> allowedGroup = new ArrayList<String>();
        allowedGroup.add(Group.ADMINS_GROUP_NAME);
        List<String> contentsId = sem.searchEntityId(null, categories, allowedGroup);
        assertNotNull(contentsId);
        String[] expected1 = { "ART122", "ART102", "ART111", "ART120" };
        this.verify(contentsId, expected1);
    } 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)

Aggregations

Category (com.agiletec.aps.system.services.category.Category)91 ArrayList (java.util.ArrayList)23 ITreeNode (com.agiletec.aps.system.common.tree.ITreeNode)9 ResourceNotFoundException (org.entando.entando.aps.system.exception.ResourceNotFoundException)7 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)6 TextAttribute (com.agiletec.aps.system.common.entity.model.attribute.TextAttribute)6 List (java.util.List)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 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 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 Cache (org.springframework.cache.Cache)4 CategoryUtilizer (com.agiletec.aps.system.services.category.CategoryUtilizer)3 HashSet (java.util.HashSet)3