}
if (contentRelationships != null) {
List<ContentletRelationshipRecords> records = contentRelationships
.getRelationshipsRecords();
for (ContentletRelationshipRecords cr : records) {
Relationship rel = cr.getRelationship();
List<Contentlet> cons = cr.getRecords();
if (cons == null) {
cons = new ArrayList<Contentlet>();
}
//There is a case when the Relationship is between same structures
//We need to validate that case
boolean isRelationshipParent = true;
if(rel.getParentStructureInode().equalsIgnoreCase(rel.getChildStructureInode())){
if(!cr.isHasParent()){
isRelationshipParent = false;
}
}
// if i am the parent
if (rel.getParentStructureInode().equalsIgnoreCase(stInode) && isRelationshipParent) {
if (rel.isChildRequired() && cons.isEmpty()) {
hasError = true;
cve.addRequiredRelationship(rel, cons);
}
for (Contentlet con : cons) {
try {
List<Contentlet> relatedCon = getRelatedContent(
con, rel, APILocator.getUserAPI()
.getSystemUser(), true);
if (rel.getCardinality() == 0
&& relatedCon.size() > 0
&& !relatedCon.get(0).getIdentifier()
.equals(contentlet.getIdentifier())) {
hasError = true;
cve.addBadCardinalityRelationship(rel, cons);
}
if (!con.getStructureInode().equalsIgnoreCase(
rel.getChildStructureInode())) {
hasError = true;
cve.addInvalidContentRelationship(rel, cons);
}
} catch (DotSecurityException e) {
Logger.error(this, "Unable to get system user", e);
} catch (DotDataException e) {
Logger.error(this, "Unable to get system user", e);
}
}
} else if (rel.getChildStructureInode().equalsIgnoreCase(
stInode)) {
if (rel.isParentRequired() && cons.isEmpty()) {
hasError = true;
cve.addRequiredRelationship(rel, cons);
}
if (rel.getCardinality() == 0 && cons.size() > 1) {
hasError = true;
cve.addBadCardinalityRelationship(rel, cons);
}
for (Contentlet con : cons) {
if (!con.getStructureInode().equalsIgnoreCase(
rel.getParentStructureInode())) {
hasError = true;
cve.addInvalidContentRelationship(rel, cons);
}
}
} else {