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