@XmlRootElement(name = "RelationshipBase")
@MappedSuperclass
@Audited
-public abstract class RelationshipBase<FROM extends IRelated, TO extends IRelated, TYPE extends RelationshipTermBase> extends ReferencedEntityBase implements Cloneable {
+public abstract class RelationshipBase<FROM extends IRelated, TO extends IRelated, TYPE extends RelationshipTermBase>
+ extends ReferencedEntityBase
+ implements Cloneable {
+
private static final long serialVersionUID = -5030154633820061997L;
@SuppressWarnings("unused")
private static final Logger logger = Logger.getLogger(RelationshipBase.class);
@XmlEnumValue("relatedFrom")
relatedFrom,
@XmlEnumValue("relatedTo")
- relatedTo
+ relatedTo;
+
+ public Direction invers(){
+ return (this == relatedFrom)? relatedTo: relatedFrom;
+ }
}
protected RelationshipBase(){
@Override
public long countTaxonRelationships(Taxon taxon, TaxonRelationshipType type,
- boolean includePublished, Direction direction) {
+ boolean includeUnpublished, Direction direction) {
AuditEvent auditEvent = getAuditEventFromContext();
if(auditEvent.equals(AuditEvent.CURRENT_VIEW)) {
- String queryString = prepareTaxonRelationshipQuery(type, includePublished, direction, true);
+ String queryString = prepareTaxonRelationshipQuery(type, includeUnpublished, direction, true);
Query query = getSession().createQuery(queryString);
query.setParameter("relatedTaxon", taxon);
if(type != null) {
query.setParameter("type",type);
}
- if(! includePublished) {
+ if(! includeUnpublished) {
query.setBoolean("publish",Boolean.TRUE);
}
/**
* @param type
- * @param includePublished
+ * @param includeUnpublished
* @param direction
* @param b
* @return
*/
- private String prepareTaxonRelationshipQuery(TaxonRelationshipType type, boolean includePublished,
+ private String prepareTaxonRelationshipQuery(TaxonRelationshipType type, boolean includeUnpublished,
Direction direction, boolean isCount) {
String selectStr = isCount? " count(rel) as n ":" rel ";
String result = "SELECT " + selectStr +
if (type != null){
result += " AND rel.type = :type ";
}
- if(! includePublished) {
- result += " AND rel."+direction+".publish = :publish";
+ if(! includeUnpublished) {
+ result += " AND rel."+direction.invers()+".publish = :publish";
}
return result;
}
@Override
public List<TaxonRelationship> getTaxonRelationships(Taxon taxon, TaxonRelationshipType type,
- boolean includePublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints,
+ boolean includeUnpublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints,
List<String> propertyPaths, Direction direction) {
AuditEvent auditEvent = getAuditEventFromContext();
if(auditEvent.equals(AuditEvent.CURRENT_VIEW)) {
- String queryString = prepareTaxonRelationshipQuery(type, includePublished, direction, false);
+ String queryString = prepareTaxonRelationshipQuery(type, includeUnpublished, direction, false);
queryString += orderByClause("rel", orderHints);
if(type != null) {
query.setParameter("type",type);
}
- if(! includePublished) {
+ if(! includeUnpublished) {
query.setBoolean("publish",Boolean.TRUE);
}
setPagingParameter(query, pageSize, pageNumber);
* @return the number of TaxonRelationship instances
*/
public long countTaxonRelationships(Taxon taxon, TaxonRelationshipType type,
- boolean includePublished, Direction direction);
+ boolean includeUnpublished, Direction direction);
/**
* Returns the TaxonRelationships (of where relationship.type == type, if
* @return a List of TaxonRelationship instances
*/
public List<TaxonRelationship> getTaxonRelationships(Taxon taxon,
- TaxonRelationshipType type, boolean includePublished,
+ TaxonRelationshipType type, boolean includeUnpublished,
Integer pageSize, Integer pageNumber,
List<OrderHint> orderHints, List<String> propertyPaths,
Direction direction);
public List<TaxonRelationship> doGetTaxonRelations(@PathVariable("uuid") UUID uuid,
HttpServletRequest request, HttpServletResponse response)throws IOException {
- boolean includePublished = NO_UNPUBLISHED;
+ boolean includeUnpublished = NO_UNPUBLISHED;
logger.info("doGetTaxonRelations()" + requestPathAndQuery(request));
Taxon taxon = getCdmBaseInstance(Taxon.class, uuid, response, (List<String>)null);
- taxon = checkExistsAndAccess(taxon, includePublished, response);
+ taxon = checkExistsAndAccess(taxon, includeUnpublished, response);
List<TaxonRelationship> toRelationships = service.listToTaxonRelationships(taxon, null,
- includePublished, null, null, null, TAXONRELATIONSHIP_INIT_STRATEGY);
+ includeUnpublished, null, null, null, TAXONRELATIONSHIP_INIT_STRATEGY);
List<TaxonRelationship> fromRelationships = service.listFromTaxonRelationships(taxon, null,
- includePublished, null, null, null, TAXONRELATIONSHIP_INIT_STRATEGY);
+ includeUnpublished, null, null, null, TAXONRELATIONSHIP_INIT_STRATEGY);
List<TaxonRelationship> allRelationships = new ArrayList<>(toRelationships.size() + fromRelationships.size());
allRelationships.addAll(toRelationships);
*
* @param taxon The taxon that is relatedTo
* @param type The type of TaxonRelationship (can be null)
- * @param includePublished should unpublished related taxa also be returned?
+ * @param includeUnpublished should unpublished related taxa also be returned?
* @param pageSize The maximum number of relationships returned (can be null for all relationships)
* @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
* @param orderHints Properties to order by
* @return a List of TaxonRelationship instances
*/
public List<TaxonRelationship> listToTaxonRelationships(Taxon taxon, TaxonRelationshipType type,
- boolean includePublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
+ boolean includeUnpublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
/**
*
* @param taxon The taxon that is relatedTo
* @param type The type of TaxonRelationship (can be null)
- * @param includePublished should unpublished related taxa also be returned?
+ * @param includeUnpublished should unpublished related taxa also be returned?
* @param pageSize The maximum number of relationships returned (can be null for all relationships)
* @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
* @param orderHints Properties to order by
* @return a Pager of TaxonRelationship instances
*/
public Pager<TaxonRelationship> pageToTaxonRelationships(Taxon taxon, TaxonRelationshipType type,
- boolean includePublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
+ boolean includeUnpublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
/**
* Returns the TaxonRelationships (of where relationship.type == type, if this argument is supplied)
*
* @param taxon The taxon that is relatedFrom
* @param type The type of TaxonRelationship (can be null)
- * @param includePublished should unpublished related taxa also be returned?
+ * @param includeUnpublished should unpublished related taxa also be returned?
* @param pageSize The maximum number of relationships returned (can be null for all relationships)
* @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
* @param orderHints Properties to order by
* @return a List of TaxonRelationship instances
*/
public List<TaxonRelationship> listFromTaxonRelationships(Taxon taxon, TaxonRelationshipType type,
- boolean includePublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
+ boolean includeUnpublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
/**
*
* @param taxon The taxon that is relatedFrom
* @param type The type of TaxonRelationship (can be null)
- * @param includePublished should unpublished related taxa also be returned?
+ * @param includeUnpublished should unpublished related taxa also be returned?
* @param pageSize The maximum number of relationships returned (can be null for all relationships)
* @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
* @param orderHints Properties to order by
* @return a Pager of TaxonRelationship instances
*/
public Pager<TaxonRelationship> pageFromTaxonRelationships(Taxon taxon, TaxonRelationshipType type,
- boolean includePublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
+ boolean includeUnpublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
/**
* lists all taxa which are related to the <code>taxon</code> given as
@Override
public List<TaxonRelationship> listToTaxonRelationships(Taxon taxon, TaxonRelationshipType type,
- boolean includePublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths){
- long numberOfResults = dao.countTaxonRelationships(taxon, type, includePublished, TaxonRelationship.Direction.relatedTo);
+ boolean includeUnpublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths){
+ long numberOfResults = dao.countTaxonRelationships(taxon, type, includeUnpublished, TaxonRelationship.Direction.relatedTo);
List<TaxonRelationship> results = new ArrayList<>();
if(numberOfResults > 0) { // no point checking again
- results = dao.getTaxonRelationships(taxon, type, includePublished, pageSize, pageNumber, orderHints, propertyPaths, TaxonRelationship.Direction.relatedTo);
+ results = dao.getTaxonRelationships(taxon, type, includeUnpublished, pageSize, pageNumber, orderHints, propertyPaths, TaxonRelationship.Direction.relatedTo);
}
return results;
}
@Override
public Pager<TaxonRelationship> pageToTaxonRelationships(Taxon taxon, TaxonRelationshipType type,
- boolean includePublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
- long numberOfResults = dao.countTaxonRelationships(taxon, type, includePublished, TaxonRelationship.Direction.relatedTo);
+ boolean includeUnpublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
+ long numberOfResults = dao.countTaxonRelationships(taxon, type, includeUnpublished, TaxonRelationship.Direction.relatedTo);
List<TaxonRelationship> results = new ArrayList<>();
if(numberOfResults > 0) { // no point checking again
- results = dao.getTaxonRelationships(taxon, type, includePublished, pageSize, pageNumber, orderHints, propertyPaths, TaxonRelationship.Direction.relatedTo);
+ results = dao.getTaxonRelationships(taxon, type, includeUnpublished, pageSize, pageNumber, orderHints, propertyPaths, TaxonRelationship.Direction.relatedTo);
}
return new DefaultPagerImpl<>(pageNumber, numberOfResults, pageSize, results);
}
@Override
public List<TaxonRelationship> listFromTaxonRelationships(Taxon taxon, TaxonRelationshipType type,
- boolean includePublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths){
- long numberOfResults = dao.countTaxonRelationships(taxon, type, includePublished, TaxonRelationship.Direction.relatedFrom);
+ boolean includeUnpublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths){
+ long numberOfResults = dao.countTaxonRelationships(taxon, type, includeUnpublished, TaxonRelationship.Direction.relatedFrom);
List<TaxonRelationship> results = new ArrayList<>();
if(numberOfResults > 0) { // no point checking again
- results = dao.getTaxonRelationships(taxon, type, includePublished, pageSize, pageNumber, orderHints, propertyPaths, TaxonRelationship.Direction.relatedFrom);
+ results = dao.getTaxonRelationships(taxon, type, includeUnpublished, pageSize, pageNumber, orderHints, propertyPaths, TaxonRelationship.Direction.relatedFrom);
}
return results;
}
@Override
public Pager<TaxonRelationship> pageFromTaxonRelationships(Taxon taxon, TaxonRelationshipType type,
- boolean includePublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
- long numberOfResults = dao.countTaxonRelationships(taxon, type, includePublished, TaxonRelationship.Direction.relatedFrom);
+ boolean includeUnpublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
+ long numberOfResults = dao.countTaxonRelationships(taxon, type, includeUnpublished, TaxonRelationship.Direction.relatedFrom);
List<TaxonRelationship> results = new ArrayList<>();
if(numberOfResults > 0) { // no point checking again
- results = dao.getTaxonRelationships(taxon, type, includePublished, pageSize, pageNumber, orderHints, propertyPaths, TaxonRelationship.Direction.relatedFrom);
+ results = dao.getTaxonRelationships(taxon, type, includeUnpublished, pageSize, pageNumber, orderHints, propertyPaths, TaxonRelationship.Direction.relatedFrom);
}
return new DefaultPagerImpl<>(pageNumber, numberOfResults, pageSize, results);
}