Search in sources :

Example 31 with ResourceInterface

use of com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface in project entando-core by entando.

the class ResourceManagerIntegrationTest method testAddRemoveImageResource.

private void testAddRemoveImageResource(String mainGroup) throws Throwable {
    List<String> allowedGroups = this.getAllGroupCodes();
    ResourceInterface res = null;
    String resDescrToAdd = "Entando Logo";
    String resourceType = "Image";
    String categoryCodeToAdd = "resCat1";
    ResourceDataBean bean = this.getMockResource(resourceType, mainGroup, resDescrToAdd, categoryCodeToAdd);
    try {
        List<String> resourcesId = _resourceManager.searchResourcesId(resourceType, null, categoryCodeToAdd, allowedGroups);
        assertEquals(1, resourcesId.size());
        this._resourceManager.addResource(bean);
        resourcesId = _resourceManager.searchResourcesId(resourceType, resDescrToAdd, null, allowedGroups);
        assertEquals(resourcesId.size(), 1);
        resourcesId = _resourceManager.searchResourcesId(resourceType, resDescrToAdd, categoryCodeToAdd, allowedGroups);
        assertEquals(resourcesId.size(), 1);
        res = this._resourceManager.loadResource(resourcesId.get(0));
        assertTrue(res instanceof ImageResource);
        assertEquals(res.getCategories().size(), 1);
        assertEquals(res.getDescription(), resDescrToAdd);
        ResourceInstance instance0 = ((ImageResource) res).getInstance(0, null);
        assertEquals("entando_logo.jpg", res.getMasterFileName());
        assertEquals("image/jpeg", instance0.getMimeType());
        resourcesId = _resourceManager.searchResourcesId(resourceType, null, categoryCodeToAdd, allowedGroups);
        assertEquals(resourcesId.size(), 2);
    } catch (Throwable t) {
        throw t;
    } finally {
        if (res != null) {
            this._resourceManager.deleteResource(res);
            List<String> resources = _resourceManager.searchResourcesId(resourceType, resDescrToAdd, null, allowedGroups);
            assertEquals(resources.size(), 0);
            resources = _resourceManager.searchResourcesId(resourceType, null, categoryCodeToAdd, allowedGroups);
            assertEquals(resources.size(), 1);
        }
    }
}
Also used : ImageResource(com.agiletec.plugins.jacms.aps.system.services.resource.model.ImageResource) MockResourceDataBean(com.agiletec.plugins.jacms.aps.system.services.resource.mock.MockResourceDataBean) ResourceDataBean(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceDataBean) ResourceInstance(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInstance) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)

Example 32 with ResourceInterface

use of com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface in project entando-core by entando.

the class ResourceAction method delete.

/**
 * This forces the deletion of a resource. NOTE! This method is invoked, in
 * the administration interface, when deleting a referenced resource.
 *
 * @return The result code.
 */
public String delete() {
    try {
        String result = this.checkDeleteResource();
        if (null != result)
            return result;
        ResourceInterface resource = this.loadResource(this.getResourceId());
        this.getResourceManager().deleteResource(resource);
    } catch (Throwable t) {
        _logger.error("error in delete", t);
        return FAILURE;
    }
    return SUCCESS;
}
Also used : ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)

Example 33 with ResourceInterface

use of com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface in project entando-core by entando.

the class ResourceAction method validate.

@Override
public void validate() {
    super.validate();
    if (null != this.getFile()) {
        ResourceInterface resourcePrototype = this.getResourceManager().createResourceType(this.getResourceType());
        this.checkRightFileType(resourcePrototype);
    }
}
Also used : ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)

Example 34 with ResourceInterface

use of com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface in project entando-core by entando.

the class ResourceAction method detail.

public String detail() {
    try {
        ResourceInterface resource = this.loadResource(this.getResourceId());
        if (null == resource) {
            return INPUT;
        }
        this.setResourceTypeCode(resource.getType());
        this.setDescr(resource.getDescription());
        List<Category> resCategories = resource.getCategories();
        for (int i = 0; i < resCategories.size(); i++) {
            Category resCat = resCategories.get(i);
            this.getCategoryCodes().add(resCat.getCode());
        }
        this.setMainGroup(resource.getMainGroup());
    } catch (Throwable t) {
        _logger.error("error in detail", t);
        return FAILURE;
    }
    return SUCCESS;
}
Also used : Category(com.agiletec.aps.system.services.category.Category) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)

Example 35 with ResourceInterface

use of com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface in project entando-core by entando.

the class TestResourceAttributeAction method initForImageRemovingTest.

private String initForImageRemovingTest() throws Throwable, ApsSystemException {
    String contentId = "ART180";
    Content content = this.getContentManager().loadContent(contentId, false);
    this.executeEdit(contentId, "admin");
    String contentOnSessionMarker = AbstractContentAction.buildContentOnSessionMarker(content, ApsAdminSystemConstants.EDIT);
    Content contentOnEdit = this.getContentOnEdit(contentOnSessionMarker);
    ImageAttribute imageAttribute = (ImageAttribute) contentOnEdit.getAttribute("Foto");
    assertEquals("44", imageAttribute.getResource("it").getId());
    assertNull(imageAttribute.getResource("en"));
    IResourceManager resourceManager = (IResourceManager) this.getService(JacmsSystemConstants.RESOURCE_MANAGER);
    ResourceInterface res = resourceManager.loadResource("22");
    assertNotNull(res);
    assertEquals("jAPS Team", res.getDescr());
    imageAttribute.getResources().put("en", res);
    return contentOnSessionMarker;
}
Also used : Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) IResourceManager(com.agiletec.plugins.jacms.aps.system.services.resource.IResourceManager) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface) ImageAttribute(com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.ImageAttribute)

Aggregations

ResourceInterface (com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)45 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)8 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)7 AttributeTracer (com.agiletec.aps.system.common.entity.model.AttributeTracer)5 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)4 Category (com.agiletec.aps.system.services.category.Category)4 AbstractResourceAttribute (com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.AbstractResourceAttribute)4 ImageResource (com.agiletec.plugins.jacms.aps.system.services.resource.model.ImageResource)4 ResourceInstance (com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInstance)3 CompositeAttribute (com.agiletec.aps.system.common.entity.model.attribute.CompositeAttribute)2 MonoListAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute)2 Lang (com.agiletec.aps.system.services.lang.Lang)2 UserDetails (com.agiletec.aps.system.services.user.UserDetails)2 AttachResource (com.agiletec.plugins.jacms.aps.system.services.resource.model.AttachResource)2 ResourceRecordVO (com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceRecordVO)2 ArrayList (java.util.ArrayList)2 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)2 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)2 MockResourcesDAO (com.agiletec.aps.services.mock.MockResourcesDAO)1 AttributeFieldError (com.agiletec.aps.system.common.entity.model.AttributeFieldError)1