Search in sources :

Example 26 with ResourceInterface

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

the class ApiResourceInterface method getResource.

public JAXBResource getResource(Properties properties) throws Throwable {
    JAXBResource jaxbResource = null;
    String id = properties.getProperty("id");
    String resourceTypeCode = properties.getProperty(RESOURCE_TYPE_CODE_PARAM);
    try {
        ResourceInterface resource = this.getResourceManager().loadResource(id);
        if (null == resource || !resource.getType().equalsIgnoreCase(resourceTypeCode)) {
            throw new ApiException(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR, "Null resource by id '" + id + "'", Response.Status.CONFLICT);
        }
        UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
        if (null == user) {
            user = this.getUserManager().getGuestUser();
        }
        String groupName = resource.getMainGroup();
        if (!Group.FREE_GROUP_NAME.equals(groupName) && !this.getAuthorizationManager().isAuthOnGroup(user, groupName)) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Required resource '" + id + "' does not allowed", Response.Status.FORBIDDEN);
        }
        jaxbResource = new JAXBResource(resource);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("error in getResource", t);
        throw new ApsSystemException("Error into API method", t);
    }
    return jaxbResource;
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) JAXBResource(org.entando.entando.plugins.jacms.aps.system.services.api.model.JAXBResource) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 27 with ResourceInterface

use of com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface 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)

Example 28 with ResourceInterface

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

the class ResourceManagerIntegrationTest method testGetResourceType.

public void testGetResourceType() {
    ResourceInterface imageResource = this._resourceManager.createResourceType("Image");
    assertEquals("", imageResource.getDescription());
    assertEquals("", imageResource.getId());
    assertEquals("Image", imageResource.getType());
}
Also used : ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)

Example 29 with ResourceInterface

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

the class ResourceManagerIntegrationTest method testCreateResourceType.

public void testCreateResourceType() {
    ResourceInterface imageResource = this._resourceManager.createResourceType("Image");
    assertNotNull(imageResource);
    assertEquals("", imageResource.getDescription());
    assertEquals("", imageResource.getId());
    assertEquals("Image", imageResource.getType());
    assertNotSame("", imageResource.getXML());
}
Also used : ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)

Example 30 with ResourceInterface

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

the class ResourceManagerIntegrationTest method testLoadResource.

public void testLoadResource() throws Throwable {
    try {
        ResourceInterface resource = this._resourceManager.loadResource("44");
        assertTrue(resource instanceof ImageResource);
        assertTrue(resource.isMultiInstance());
        assertEquals(resource.getDescription(), "logo");
        assertEquals(resource.getCategories().size(), 1);
        resource = this._resourceManager.loadResource("7");
        assertTrue(resource instanceof AttachResource);
        assertFalse(resource.isMultiInstance());
        assertEquals(resource.getDescription(), "configurazione");
        assertEquals(resource.getCategories().size(), 0);
    } catch (Throwable t) {
        throw t;
    }
}
Also used : ImageResource(com.agiletec.plugins.jacms.aps.system.services.resource.model.ImageResource) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface) AttachResource(com.agiletec.plugins.jacms.aps.system.services.resource.model.AttachResource)

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