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