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;
}
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);
}
}
}
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());
}
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());
}
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;
}
}
Aggregations