* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
-
package eu.etaxonomy.cdm.common;
import java.io.BufferedReader;
}
return -1;
}
+
+ public static String userFriendlyCamelCase(String camelCase){
+ return String.join(" ", StringUtils.splitByCharacterTypeCamelCase(camelCase));
+ }
+
+ public static String userFriendlyClassName(Class<?> clazz){
+ return userFriendlyCamelCase(clazz.getSimpleName());
+ }
}
import org.apache.commons.lang3.StringUtils;
-import eu.etaxonomy.cdm.common.CdmUtils;
-import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.common.Language;
import eu.etaxonomy.cdm.model.description.CommonTaxonName;
-import eu.etaxonomy.cdm.model.description.DescriptionBase;
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
import eu.etaxonomy.cdm.model.description.Distribution;
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
-import eu.etaxonomy.cdm.model.description.SpecimenDescription;
-import eu.etaxonomy.cdm.model.description.TaxonDescription;
import eu.etaxonomy.cdm.model.description.TaxonInteraction;
-import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
import eu.etaxonomy.cdm.model.description.TextData;
import eu.etaxonomy.cdm.model.location.NamedArea;
-import eu.etaxonomy.cdm.model.name.TaxonName;
-import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
import eu.etaxonomy.cdm.model.taxon.Taxon;
/**
public static String format(DescriptionElementBase element, Language defaultLanguage){
- String mainElementLabel= null;
- DescriptionBase<?> descr = element.getInDescription();
- descr = CdmBase.deproxy(descr);
-
- if (descr != null){
- if (descr.isInstanceOf(TaxonDescription.class)){
- Taxon taxon = CdmBase.deproxy(descr, TaxonDescription.class).getTaxon();
- if (taxon != null){
- mainElementLabel = taxon.getTitleCache();
- }
- }else if (descr.isInstanceOf(SpecimenDescription.class)){
- SpecimenOrObservationBase<?> specimen = CdmBase.deproxy(descr, SpecimenDescription.class).getDescribedSpecimenOrObservation();
- if (specimen != null){
- mainElementLabel = specimen.getTitleCache();
- }
- }else if (descr.isInstanceOf(TaxonNameDescription.class)){
- TaxonName name = CdmBase.deproxy(descr, TaxonNameDescription.class).getTaxonName();
- if (name != null){
- mainElementLabel = name.getTitleCache();
- }
- }
- }
+// String mainElementLabel= null;
+// DescriptionBase<?> descr = element.getInDescription();
+// descr = CdmBase.deproxy(descr);
+//
+// if (descr != null){
+// IDescribable<?> target = CdmBase.deproxy(descr.describedEntity());
+// if (target != null){
+// mainElementLabel = target.getTitleCache();
+// }else{
+// return descr.getTitleCache();
+// }
+// }
String cache = null;
if (element instanceof TextData) {
}
if (element instanceof Distribution) {
Distribution distribution = (Distribution) element;
-
NamedArea area = distribution.getArea();
if(area != null){
cache = area.getLabel();
}
}
String result = cache == null ? "" : cache;
- if (isNotBlank(mainElementLabel)){
- result = CdmUtils.concat(" ", result, "(" + mainElementLabel + ")");
- }
+// if (isNotBlank(mainElementLabel)){
+// result = CdmUtils.concat(" ", result, "(" + mainElementLabel + ")");
+// }
return result;
}
}
//from taxeditor DescriptionHelper
- public static String getCache(DescriptionElementBase element,
+ private static String getCache(DescriptionElementBase element,
Language defaultLanguage) {
String mainElementLabel= null;
import org.hibernate.search.annotations.Store;
import org.joda.time.DateTime;
+import eu.etaxonomy.cdm.common.CdmUtils;
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
import eu.etaxonomy.cdm.hibernate.search.DateTimeBridge;
import eu.etaxonomy.cdm.hibernate.search.NotNullAwareIdBridge;
@Transient
@Override
public String getUserFriendlyTypeName(){
- return String.join(" ",StringUtils.splitByCharacterTypeCamelCase(getClass().getSimpleName()));
+ return CdmUtils.userFriendlyClassName(getClass());
}
@Transient
import org.springframework.stereotype.Repository;
import eu.etaxonomy.cdm.common.CdmUtils;
-import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
-import eu.etaxonomy.cdm.model.name.HybridRelationship;
+import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
+import eu.etaxonomy.cdm.model.common.SingleSourcedEntityBase;
import eu.etaxonomy.cdm.model.reference.ISourceable;
import eu.etaxonomy.cdm.model.reference.NamedSourceBase;
import eu.etaxonomy.cdm.model.reference.OriginalSourceBase;
super(OriginalSourceBase.class);
}
+ @Override
+ public <S extends SingleSourcedEntityBase> S findSingleSourceBySourceId(Class<S> clazz, int sourceId){
+ if (clazz == null){
+ clazz = (Class)SingleSourcedEntityBase.class;
+ }
+ Query q = getSession().createQuery(
+ "SELECT c " +
+ "FROM " + clazz.getSimpleName() + " AS c " +
+ "INNER JOIN c.source AS source " +
+ "WHERE source.id= :sourceId "
+ );
+ q.setInteger("sourceId", sourceId);
+
+ @SuppressWarnings("unchecked")
+ S result = (S)q.uniqueResult();
+ return result;
+ }
+
+ @Override
+ public <S extends IdentifiableEntity> S findIdentifiableBySourceId(Class<S> clazz, int sourceId){
+ if (clazz == null){
+ clazz = (Class)IdentifiableEntity.class;
+ }
+ Query q = getSession().createQuery(
+ "SELECT c " +
+ "FROM " + clazz.getSimpleName() + " AS c " +
+ "INNER JOIN c.sources AS source " +
+ "WHERE source.id= :sourceId "
+ );
+ q.setInteger("sourceId", sourceId);
+
+ @SuppressWarnings("unchecked")
+ S result = (S)q.uniqueResult();
+ return result;
+ }
+
@Override
public <S extends ISourceable> Map<String, S> findOriginalSourcesByIdInSource(Class<S> clazz, Set<String> idInSourceSet, String idNamespace) {
crit.add(Restrictions.eq("idNamespace", idNamespace));
}
crit.addOrder(Order.desc("created"));
- @SuppressWarnings({ "unchecked", "rawtypes" })
+ @SuppressWarnings({ "unchecked"})
List<OriginalSourceBase> results = crit.list();
return results;
}
@Override
- public <T extends NamedSourceBase> Long countWithNameUsedInSource(Class<T> clazz){
- Criteria criteria = getSession().createCriteria(HybridRelationship.class);
+ public <T extends NamedSourceBase> Long countWithNameUsedInSource(Class<T> clazz){
- clazz = clazz != null? clazz : (Class<T>) DescriptionElementSource.class;
+ clazz = clazz != null? clazz : (Class<T>)NamedSourceBase.class;
Criteria crit = getSession().createCriteria(clazz);
//count
- criteria.setProjection(Projections.rowCount());
- long result = (Long)criteria.uniqueResult();
+ crit.setProjection(Projections.rowCount());
+ long result = (Long)crit.uniqueResult();
return result;
}
@Override
public <T extends NamedSourceBase> List<T> listWithNameUsedInSource(Class<T> clazz,
Integer pageSize, Integer pageNumber,List<OrderHint> orderHints, List<String> propertyPaths){
+
clazz = clazz != null? clazz : (Class<T>) NamedSourceBase.class;
Criteria crit = getSession().createCriteria(clazz);
crit.add(Restrictions.isNotNull("nameUsedInSource"));
import java.util.Map;
import java.util.Set;
+import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
+import eu.etaxonomy.cdm.model.common.SingleSourcedEntityBase;
import eu.etaxonomy.cdm.model.reference.ISourceable;
import eu.etaxonomy.cdm.model.reference.NamedSourceBase;
import eu.etaxonomy.cdm.model.reference.OriginalSourceBase;
public <T extends NamedSourceBase> Long countWithNameUsedInSource(Class<T> clazz);
+ public <S extends IdentifiableEntity> S findIdentifiableBySourceId(Class<S> clazz, int sourceId);
+
+ public <S extends SingleSourcedEntityBase> S findSingleSourceBySourceId(Class<S> clazz, int sourceId);
+
}
}
public ReferencingObjectDto(CdmBase referencedEntity) {
- super((Class<CdmBase>)referencedEntity.getClass(), referencedEntity.getUuid(), referencedEntity.getId(), null);
+ super(referencedEntity.getClass(), referencedEntity.getUuid(), referencedEntity.getId(), null);
this.referencedEntity = referencedEntity;
}
@Override
public String toString() {
- return "RefObjDto[type=" + getType() + ":" + getId() + "]";
+ return "RefObjDto[type=" + (getType()!=null? getType().getSimpleName():"-") + ":" + getId() + "]";
}
-
-
}
\ No newline at end of file
\r
import eu.etaxonomy.cdm.format.ReferencingObjectFormatter;\r
import eu.etaxonomy.cdm.model.common.CdmBase;\r
+import eu.etaxonomy.cdm.model.common.IdentifiableEntity;\r
+import eu.etaxonomy.cdm.model.common.IdentifiableSource;\r
import eu.etaxonomy.cdm.model.common.Language;\r
+import eu.etaxonomy.cdm.model.common.SingleSourcedEntityBase;\r
+import eu.etaxonomy.cdm.model.description.DescriptionBase;\r
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;\r
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;\r
import eu.etaxonomy.cdm.model.metadata.CdmMetaData;\r
import eu.etaxonomy.cdm.model.metadata.CdmMetaDataPropertyName;\r
import eu.etaxonomy.cdm.model.name.NomenclaturalSource;\r
import eu.etaxonomy.cdm.model.reference.ISourceable;\r
+import eu.etaxonomy.cdm.model.reference.NamedSource;\r
import eu.etaxonomy.cdm.model.taxon.SecundumSource;\r
import eu.etaxonomy.cdm.persistence.dao.common.ICdmGenericDao;\r
import eu.etaxonomy.cdm.persistence.dao.reference.IOriginalSourceDao;\r
public Set<ReferencingObjectDto> initializeReferencingObjectDtos(Set<ReferencingObjectDto> dtos,\r
boolean doReferencingEntity, boolean doTargetEntity, boolean doDescription, Language language) {\r
\r
-// Set<ReferencingObjectDto> result = new HashSet<>();\r
for (ReferencingObjectDto dto : dtos){\r
//TODO or load()?\r
CdmBase entity = this.genericDao.find(dto.getType(), dto.getUuid());\r
targetEntity = getTarget(element);\r
}else if (entity instanceof DescriptionElementBase){\r
targetEntity = getTarget((DescriptionElementBase)entity);\r
+ }else if (entity instanceof IdentifiableSource){\r
+ IdentifiableSource source = ((IdentifiableSource) entity);\r
+ targetEntity = originalSourceDao.findIdentifiableBySourceId(IdentifiableEntity.class, source.getId());\r
+ }else if (entity instanceof NamedSource){\r
+ NamedSource source = ((NamedSource) entity);\r
+ SingleSourcedEntityBase singleSourced = originalSourceDao.findSingleSourceBySourceId(SingleSourcedEntityBase.class, source.getId());\r
+ if (singleSourced != null){\r
+ targetEntity = singleSourced;\r
+ }else{\r
+ //TODO\r
+ targetEntity = entity;\r
+ }\r
+ }else if (entity instanceof DescriptionBase){\r
+ targetEntity = getTarget((DescriptionBase)entity);\r
}else{\r
targetEntity = entity;\r
}\r
}\r
\r
private CdmBase getTarget(DescriptionElementBase element) {\r
- return (CdmBase)element.getInDescription().describedEntity();\r
+ return getTarget(element.getInDescription());\r
+ }\r
+\r
+ private CdmBase getTarget(DescriptionBase db) {\r
+ return db.describedEntity() != null ? (CdmBase)db.describedEntity() : db;\r
}\r
\r
private String getReferencingObjectDescription(CdmBase entity, Language language) {\r