use of com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface in project entando-core by entando.
the class ApsEntity method getEntityPrototype.
/**
* Create an object from the prototype.
* @return The object created from the prototype.
*/
@Override
public IApsEntity getEntityPrototype() {
IApsEntity entity = null;
try {
Class entityClass = Class.forName(this.getClass().getName());
entity = (IApsEntity) entityClass.newInstance();
entity.setId(null);
entity.setTypeCode(this.getTypeCode());
entity.setTypeDescription(this.getTypeDescription());
entity.setDescription(this.getDescription());
AttributeInterface attr;
for (int i = 0; i < this._attributeList.size(); i++) {
attr = (AttributeInterface) this._attributeList.get((i));
attr = (AttributeInterface) attr.getAttributePrototype();
attr.setParentEntity(entity);
entity.addAttribute(attr);
}
entity.setEntityDOM(this.getEntityDOM());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
_logger.error("Error creating entity prototype", e);
throw new RuntimeException("Error creating entity prototype", e);
}
return entity;
}
use of com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface in project entando-core by entando.
the class ApsEntity method validate.
@Override
public List<FieldError> validate(IGroupManager groupManager) {
List<FieldError> errors = new ArrayList<>();
if (null != this.getMainGroup() && null == groupManager.getGroup(this.getMainGroup())) {
FieldError error = new FieldError("mainGroup", FieldError.INVALID);
error.setMessage("Invalid main group - " + this.getMainGroup());
errors.add(error);
}
if (null != this.getGroups()) {
Iterator<String> groupsIter = this.getGroups().iterator();
while (groupsIter.hasNext()) {
String groupName = groupsIter.next();
if (null == groupManager.getGroup(groupName)) {
FieldError error = new FieldError("extraGroup", FieldError.INVALID);
error.setMessage("Invalid extra group - " + groupName);
errors.add(error);
}
}
}
if (null != this.getAttributeList()) {
List<AttributeInterface> attributes = this.getAttributeList();
for (int i = 0; i < attributes.size(); i++) {
AttributeInterface attribute = attributes.get(i);
AttributeTracer tracer = new AttributeTracer();
List<AttributeFieldError> attributeErrors = attribute.validate(tracer);
if (null != attributeErrors) {
errors.addAll(attributeErrors);
}
}
}
return errors;
}
use of com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface in project entando-core by entando.
the class JAXBEntity method buildEntity.
public IApsEntity buildEntity(IApsEntity prototype, ICategoryManager categoryManager) {
try {
prototype.setDescription(this.getDescription());
prototype.setId(this.getId());
prototype.setMainGroup(this.getMainGroup());
prototype.setTypeCode(this.getTypeCode());
prototype.setTypeDescription(this.getTypeDescription());
if (null != this.getGroups() && !this.getGroups().isEmpty()) {
Iterator<String> iter = this.getGroups().iterator();
while (iter.hasNext()) {
prototype.addGroup(iter.next());
}
}
if (null != this.getCategories() && !this.getCategories().isEmpty()) {
Iterator<String> iter = this.getCategories().iterator();
while (iter.hasNext()) {
String categoryCode = iter.next();
Category category = categoryManager.getCategory(categoryCode);
if (null != category) {
prototype.addCategory(category);
}
}
}
if (null == this.getAttributes()) {
return prototype;
}
for (int i = 0; i < this.getAttributes().size(); i++) {
AbstractJAXBAttribute jaxrAttribute = this.getAttributes().get(i);
AttributeInterface attribute = (AttributeInterface) prototype.getAttribute(jaxrAttribute.getName());
if (null != attribute && attribute.getType().equals(jaxrAttribute.getType())) {
attribute.valueFrom(jaxrAttribute);
}
}
} catch (Throwable t) {
_logger.error("Error creating Entity", t);
throw new RuntimeException("Error creating Entity", t);
}
return prototype;
}
use of com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface in project entando-core by entando.
the class ContentInspectionAction method getReferencedContentsId.
/**
* Return the list of the id of the referenced contents
* @return The list of content id.
*/
public List<String> getReferencedContentsId() {
List<String> referencedContentsId = new ArrayList<String>();
try {
Content content = this.getContent();
if (null == content)
return referencedContentsId;
EntityAttributeIterator attributeIter = new EntityAttributeIterator(content);
while (attributeIter.hasNext()) {
AttributeInterface currAttribute = (AttributeInterface) attributeIter.next();
if (currAttribute instanceof IReferenceableAttribute) {
IReferenceableAttribute cmsAttribute = (IReferenceableAttribute) currAttribute;
List<CmsAttributeReference> refs = cmsAttribute.getReferences(this.getLangs());
for (int scanRefs = 0; scanRefs < refs.size(); scanRefs++) {
CmsAttributeReference ref = refs.get(scanRefs);
String contentId = ref.getRefContent();
if (null == contentId)
continue;
if (!referencedContentsId.contains(contentId))
referencedContentsId.add(contentId);
}
}
}
} catch (Throwable t) {
_logger.error("Error getting referenced contents id by content {}", this.getContentId(), t);
String msg = "Error getting referenced contents id by content " + this.getContentId();
throw new RuntimeException(msg, t);
}
return referencedContentsId;
}
use of com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface in project entando-core by entando.
the class ContentInspectionAction method getReferencedPages.
public List<IPage> getReferencedPages() {
List<IPage> referencedPages = new ArrayList<IPage>();
try {
Content content = this.getContent();
if (null == content)
return referencedPages;
EntityAttributeIterator attributeIter = new EntityAttributeIterator(content);
while (attributeIter.hasNext()) {
AttributeInterface currAttribute = (AttributeInterface) attributeIter.next();
if (currAttribute instanceof IReferenceableAttribute) {
IReferenceableAttribute cmsAttribute = (IReferenceableAttribute) currAttribute;
List<CmsAttributeReference> refs = cmsAttribute.getReferences(this.getLangs());
for (int scanRefs = 0; scanRefs < refs.size(); scanRefs++) {
CmsAttributeReference ref = refs.get(scanRefs);
if (null == ref.getRefPage())
continue;
IPage page = this.getPageManager().getOnlinePage(ref.getRefPage());
if (null == page)
continue;
if (!referencedPages.contains(page)) {
referencedPages.add(page);
}
}
}
}
} catch (Throwable t) {
_logger.error("Error getting referenced pages by content {}", this.getContentId(), t);
String msg = "Error getting referenced pages by content " + this.getContentId();
throw new RuntimeException(msg, t);
}
return referencedPages;
}
Aggregations