Search in sources :

Example 41 with ResourceInterface

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

the class AbstractResourceAttribute method getJAXBAttribute.

@Override
public AbstractJAXBAttribute getJAXBAttribute(String langCode) {
    JAXBResourceAttribute jaxbResourceAttribute = (JAXBResourceAttribute) super.createJAXBAttribute(langCode);
    if (null == jaxbResourceAttribute) {
        return null;
    }
    if (null == langCode) {
        langCode = this.getDefaultLangCode();
    }
    ResourceInterface resource = this.getResource(langCode);
    if (null == resource) {
        return jaxbResourceAttribute;
    }
    JAXBResourceValue value = new JAXBResourceValue();
    try {
        String text = this.getTextForLang(langCode);
        value.setText(text);
        this.setRenderingLang(langCode);
        String path = this.getDefaultPath();
        value.setPath(path);
        value.setResourceId(resource.getId());
        StringBuilder restResourcePath = new StringBuilder();
        restResourcePath.append(this.getConfigManager().getParam("applicationBaseURL"));
        restResourcePath.append("api/rs/").append(langCode).append("/jacms/");
        if (this.getType().equals(JacmsSystemConstants.RESOURE_ATTACH_CODE)) {
            restResourcePath.append("attachment");
        } else {
            restResourcePath.append("image");
        }
        restResourcePath.append("?id=").append(resource.getId());
        value.setRestResourcePath(restResourcePath.toString());
    } catch (Throwable t) {
        logger.error("Error creating jaxb response. lang: {}", langCode, t);
        throw new RuntimeException("Error creating jaxb response", t);
    }
    jaxbResourceAttribute.setResource(value);
    return jaxbResourceAttribute;
}
Also used : ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)

Example 42 with ResourceInterface

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

the class AttachAttribute method getIndexeableFieldValue.

@Override
public String getIndexeableFieldValue() {
    StringBuilder buffer = new StringBuilder();
    if (null != super.getIndexeableFieldValue()) {
        buffer.append(super.getIndexeableFieldValue());
    }
    String extraValue = null;
    ResourceInterface resource = this.getResource();
    if (resource != null) {
        InputStream is = ((AttachResource) resource).getResourceStream();
        if (null != is) {
            AutoDetectParser parser = new AutoDetectParser();
            BodyContentHandler handler = new BodyContentHandler(-1);
            Metadata metadata = new Metadata();
            try {
                parser.parse(is, handler, metadata);
                extraValue = handler.toString();
            } catch (Throwable t) {
                _logger.error("Error while processing the parsing", t);
            } finally {
                try {
                    is.close();
                } catch (IOException ex) {
                    _logger.error("Error closing stream", ex);
                }
            }
        }
    }
    if (null != extraValue) {
        buffer.append(" ").append(extraValue);
    }
    return buffer.toString();
}
Also used : BodyContentHandler(org.apache.tika.sax.BodyContentHandler) InputStream(java.io.InputStream) Metadata(org.apache.tika.metadata.Metadata) AutoDetectParser(org.apache.tika.parser.AutoDetectParser) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface) IOException(java.io.IOException) AttachResource(com.agiletec.plugins.jacms.aps.system.services.resource.model.AttachResource)

Example 43 with ResourceInterface

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

the class ResourceManager method addResource.

/**
 * Salva una risorsa nel db con incluse nel filesystem, indipendentemente dal tipo.
 * @param bean L'oggetto detentore dei dati della risorsa da inserire.
 * @throws ApsSystemException in caso di errore.
 */
@Override
public ResourceInterface addResource(ResourceDataBean bean) throws ApsSystemException {
    ResourceInterface newResource = this.createResource(bean);
    try {
        this.generateAndSetResourceId(newResource, bean.getResourceId());
        newResource.saveResourceInstances(bean);
        this.getResourceDAO().addResource(newResource);
    } catch (Throwable t) {
        newResource.deleteResourceInstances();
        logger.error("Error adding resource", t);
        throw new ApsSystemException("Error adding resource", t);
    }
    return newResource;
}
Also used : ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)

Example 44 with ResourceInterface

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

the class TestValidateResourceAttribute method testValidate_Single.

protected void testValidate_Single(String attributeName, String testResourceId) throws Throwable {
    try {
        String contentOnSessionMarker = this.executeCreateNewContent();
        Content content = this.getContentOnEdit(contentOnSessionMarker);
        AttributeTracer tracer = this.getTracer();
        AttributeInterface resourceAttribute = (AttributeInterface) content.getAttribute(attributeName);
        String formFieldName = tracer.getFormFieldName(resourceAttribute);
        String resourceFieldName = resourceAttribute.getType() + ":" + attributeName;
        this.initSaveContentAction(contentOnSessionMarker);
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(0, resourceFieldName);
        this.checkFieldErrors(0, formFieldName);
        this.initSaveContentAction(contentOnSessionMarker);
        this.addParameter(formFieldName, "resourceDescription");
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(1, resourceFieldName);
        content = this.getContentOnEdit(contentOnSessionMarker);
        AbstractResourceAttribute attachAttribute = (AbstractResourceAttribute) content.getAttribute(attributeName);
        ResourceInterface resource = this._resourceManager.loadResource(testResourceId);
        attachAttribute.setResource(resource, this.getLangManager().getDefaultLang().getCode());
        this.initSaveContentAction(contentOnSessionMarker);
        this.executeAction(Action.INPUT);
        this.checkFieldErrors(0, resourceFieldName);
    } catch (Throwable t) {
        this.deleteTestContent();
        throw t;
    }
}
Also used : AbstractResourceAttribute(com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.AbstractResourceAttribute) AttributeTracer(com.agiletec.aps.system.common.entity.model.AttributeTracer) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)

Example 45 with ResourceInterface

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

the class CmsCacheWrapperManager method updateFromResourceChanged.

@Override
public void updateFromResourceChanged(ResourceChangedEvent event) {
    try {
        ResourceInterface resource = event.getResource();
        if (null == resource) {
            return;
        }
        List<String> utilizers = ((ResourceUtilizer) this.getContentManager()).getResourceUtilizers(resource.getId());
        for (int i = 0; i < utilizers.size(); i++) {
            String contentId = utilizers.get(i);
            Content content = this.getContentManager().loadContent(contentId, true);
            if (null != content) {
                this.releaseRelatedItems(content);
            }
        }
    } catch (Throwable t) {
        _logger.error("Error notifing event {}", ResourceChangedEvent.class.getName(), t);
    }
}
Also used : Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface) ResourceUtilizer(com.agiletec.plugins.jacms.aps.system.services.resource.ResourceUtilizer)

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