Search in sources :

Example 6 with ResourceInterface

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);
    }
}
Also used : ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)

Example 7 with ResourceInterface

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;
}
Also used : ResourceRecordVO(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceRecordVO) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)

Example 8 with ResourceInterface

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);
}
Also used : ImageResource(com.agiletec.plugins.jacms.aps.system.services.resource.model.ImageResource) ResourceRecordVO(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceRecordVO) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface) MockResourcesDAO(com.agiletec.aps.services.mock.MockResourcesDAO) DataSource(javax.sql.DataSource)

Example 9 with ResourceInterface

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;
}
Also used : AttributeTracer(com.agiletec.aps.system.common.entity.model.AttributeTracer) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) AttributeFieldError(com.agiletec.aps.system.common.entity.model.AttributeFieldError) Lang(com.agiletec.aps.system.services.lang.Lang) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)

Example 10 with ResourceInterface

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);
    }
}
Also used : ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)

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