* @throws DotDataException
*/
public List<Contentlet> pullRelatedContent (String relationshipName, String contentletInode, int limit, String orderBy) {
ContentletAPI conAPI = APILocator.getContentletAPI();
Contentlet contentlet = null;
try {
contentlet = conAPI.find(contentletInode, APILocator.getUserAPI().getSystemUser(), true);
} catch (DotSecurityException e) {
Logger.info(this, "Unable to look up content because of a problem getting the system user");
} catch (DotDataException de) {
Logger.info(this, "Unable to retrieve content with inode = " + contentletInode);
}
Relationship relationship = RelationshipFactory.getRelationshipByRelationTypeValue(relationshipName);
if(contentlet == null || !InodeUtils.isSet(contentlet.getInode()) || relationship == null || !InodeUtils.isSet(relationship.getInode()))
return new ArrayList<Contentlet>();
if(UtilMethods.isSet(orderBy)) {
String[] orderBySplitted = orderBy != null?orderBy.split("[,\\s]+"):new String[0];
for (String orderBySeg : orderBySplitted) {
orderBySeg = orderBySeg.trim();
if(orderBySeg.toLowerCase().equals("desc") || orderBySeg.toLowerCase().equals("asc"))
continue;
if(orderBySeg.toLowerCase().equals("moddate")) {
orderBy = orderBy.replaceAll("(?i)moddate", "mod_date");
continue;
}
Field field = FieldFactory.getFieldByVariableName(contentlet.getStructureInode(), orderBySeg);
if (field != null && InodeUtils.isSet(field.getInode()))
orderBy = orderBy.replaceAll(orderBySeg, field.getFieldContentlet());
}
}
return RelationshipFactory.getRelatedContentlets(relationship, contentlet, orderBy, null, true, limit);