use of com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface in project entando-core by entando.
the class ResourceManager method updateResource.
@Override
public void updateResource(ResourceDataBean bean) throws ApsSystemException {
ResourceInterface oldResource = this.loadResource(bean.getResourceId());
try {
if (null == bean.getInputStream()) {
oldResource.setDescription(bean.getDescr());
oldResource.setCategories(bean.getCategories());
this.getResourceDAO().updateResource(oldResource);
this.notifyResourceChanging(oldResource);
} else {
// this.saveResource(bean);
ResourceInterface updatedResource = this.createResource(bean);
updatedResource.saveResourceInstances(bean);
this.getResourceDAO().updateResource(updatedResource);
if (!updatedResource.getMasterFileName().equals(oldResource.getMasterFileName())) {
oldResource.deleteResourceInstances();
}
this.notifyResourceChanging(updatedResource);
}
} catch (Throwable t) {
logger.error("Error updating resource", t);
throw new ApsSystemException("Error updating resource", t);
}
}
use of com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface in project entando-core by entando.
the class ResourceManager method loadResource.
/**
* Restituisce la risorsa con l'id specificato.
* @param id L'identificativo della risorsa da caricare.
* @return La risorsa cercata. null se non vi รจ nessuna risorsa con l'identificativo immesso.
* @throws ApsSystemException in caso di errore.
*/
@Override
public ResourceInterface loadResource(String id) throws ApsSystemException {
ResourceInterface resource = null;
try {
ResourceRecordVO resourceVo = this.getResourceDAO().loadResourceVo(id);
if (null != resourceVo) {
resource = this.createResource(resourceVo);
resource.setMasterFileName(resourceVo.getMasterFileName());
}
} catch (Throwable t) {
logger.error("Error loading resource : id {}", id, t);
throw new ApsSystemException("Error loading resource : id " + id, t);
}
return resource;
}
use of com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface in project entando-core by entando.
the class TestResourceDAO method testAddDeleteResource.
public void testAddDeleteResource() throws Throwable {
DataSource dataSource = (DataSource) this.getApplicationContext().getBean("portDataSource");
MockResourcesDAO mockResourcesDao = new MockResourcesDAO();
mockResourcesDao.setDataSource(dataSource);
ResourceInterface resource = new ImageResource();
resource.setId("temp");
resource.setDescr("temp");
resource.setMainGroup(Group.FREE_GROUP_NAME);
resource.setType("Image");
resource.setFolder("/temp");
// resource.setBaseURL("temp");
ResourceRecordVO resourceRecordVO = null;
try {
mockResourcesDao.deleteResource("temp");
} catch (Throwable t) {
throw t;
}
_resourceDao.addResource(resource);
resourceRecordVO = _resourceDao.loadResourceVo(resource.getId());
assertEquals(resourceRecordVO.getDescr().equals("temp"), true);
_resourceDao.deleteResource(resource.getId());
resourceRecordVO = _resourceDao.loadResourceVo(resource.getId());
assertNull(resourceRecordVO);
}
use of com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface in project entando-core by entando.
the class AbstractResourceAttribute method validate.
@Override
public List<AttributeFieldError> validate(AttributeTracer tracer) {
List<AttributeFieldError> errors = super.validate(tracer);
try {
if (null == this.getResources()) {
return errors;
}
List<Lang> langs = super.getLangManager().getLangs();
for (int i = 0; i < langs.size(); i++) {
Lang lang = langs.get(i);
ResourceInterface resource = this.getResource(lang.getCode());
if (null == resource) {
continue;
}
AttributeTracer resourceTracer = (AttributeTracer) tracer.clone();
resourceTracer.setLang(lang);
String resourceMainGroup = resource.getMainGroup();
Content parentContent = (Content) this.getParentEntity();
if (!resourceMainGroup.equals(Group.FREE_GROUP_NAME) && !resourceMainGroup.equals(parentContent.getMainGroup()) && !parentContent.getGroups().contains(resourceMainGroup)) {
AttributeFieldError fieldError = new AttributeFieldError(this, ICmsAttributeErrorCodes.INVALID_RESOURCE_GROUPS, resourceTracer);
fieldError.setMessage("Invalid resource group - " + resourceMainGroup);
errors.add(fieldError);
}
}
} catch (Throwable t) {
logger.error("Error validating text attribute", t);
throw new RuntimeException("Error validating text attribute", t);
}
return errors;
}
use of com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface in project entando-core by entando.
the class AbstractResourceAttribute method valueFrom.
@Override
public void valueFrom(AbstractJAXBAttribute jaxbAttribute) {
super.valueFrom(jaxbAttribute);
JAXBResourceValue value = ((JAXBResourceAttribute) jaxbAttribute).getResource();
if (null == value) {
return;
}
Object resourceId = value.getResourceId();
if (null == resourceId) {
return;
}
try {
ResourceInterface resource = this.getResourceManager().loadResource(resourceId.toString());
if (null != resource) {
this.setResource(resource, this.getDefaultLangCode());
}
Object text = value.getText();
if (null == text) {
return;
}
this.getTextMap().put(this.getDefaultLangCode(), text.toString());
} catch (Exception e) {
logger.error("Error extracting resource from jaxbAttribute", e);
}
}
Aggregations