implements ICdmImport<CONFIG, STATE>{
private static final long serialVersionUID = 8730012744209195616L;
- private static Logger logger = Logger.getLogger(CdmImportBase.class);
+ private static final Logger logger = Logger.getLogger(CdmImportBase.class);
protected static final boolean CREATE = true;
protected static final boolean IMAGE_GALLERY = true;
}
}
-
+ protected Media getImageMedia(String uriString, boolean readMediaData) throws MalformedURLException {
+ return getImageMedia(uriString, null, readMediaData);
+ }
/**
* Creates
* @return
* @throws MalformedURLException
*/
- protected Media getImageMedia(String uriString, boolean readMediaData) throws MalformedURLException {
+ protected Media getImageMedia(String uriString, String uriStrThumb, boolean readMediaData) throws MalformedURLException {
if( uriString == null){
return null;
} else {
- ImageInfo imageInfo = null;
- URI uri;
uriString = uriString.replace(" ", "%20"); //replace whitespace
try {
- uri = new URI(uriString);
- try {
+ ImageInfo imageInfo = null;
+ URI uri = new URI(uriString);
+
+ try {
if (readMediaData){
logger.info("Read media data from: " + uri);
imageInfo = ImageInfo.NewInstance(uri, 0);
fireWarningEvent(message, "unknown location", 2, 0);
}
ImageFile imageFile = ImageFile.NewInstance(uri, null, imageInfo);
+
MediaRepresentation representation = MediaRepresentation.NewInstance();
+
if(imageInfo != null){
representation.setMimeType(imageInfo.getMimeType());
representation.setSuffix(imageInfo.getSuffix());
}
representation.addRepresentationPart(imageFile);
Media media = Media.NewInstance();
- media.addRepresentation(representation);
+ media.addRepresentation(representation);
+
+ if (uriStrThumb != null){
+ ImageInfo imageInfoThumb = null;
+ uriStrThumb = uriStrThumb.replace(" ", "%20"); //replace whitespace
+ URI uriThumb = new URI(uriStrThumb);
+ try {
+ if (readMediaData){
+ logger.info("Read media data from: " + uriThumb);
+ imageInfoThumb = ImageInfo.NewInstance(uriThumb, 0);
+ }
+ } catch (Exception e) {
+ String message = "An error occurred when trying to read image meta data for " + uriThumb.toString() + ": " + e.getMessage();
+ logger.warn(message);
+ fireWarningEvent(message, "unknown location", 2, 0);
+ }
+
+ ImageFile imageFileFhumb = ImageFile.NewInstance(uriThumb, null, imageInfoThumb);
+ MediaRepresentation reprThumb = MediaRepresentation.NewInstance();
+ if(imageInfoThumb != null){
+ reprThumb.setMimeType(imageInfoThumb.getMimeType());
+ reprThumb.setSuffix(imageInfoThumb.getSuffix());
+ }
+ reprThumb.addRepresentationPart(imageFileFhumb);
+ media.addRepresentation(reprThumb);
+ }
+
return media;
} catch (URISyntaxException e1) {
String message = "An URISyntaxException occurred when trying to create uri from multimedia objcet string: " + uriString;
* @param toName the taxon name of the target for this new name relationship
* @param type the type of this new name relationship
* @param ruleConsidered the string which specifies the rule on which this name relationship is based
+ * @return
* @see #getRelationsToThisName()
* @see #getNameRelations()
* @see #addRelationshipFromName(TaxonNameBase, NameRelationshipType, String)
* @see #addNameRelationship(NameRelationship)
*/
- public void addRelationshipToName(TaxonNameBase toName, NameRelationshipType type, String ruleConsidered);
+ public NameRelationship addRelationshipToName(TaxonNameBase toName, NameRelationshipType type, String ruleConsidered);
/**
* Creates a new {@link NameRelationship#NameRelationship(TaxonNameBase, TaxonNameBase, NameRelationshipType, String) name relationship} from <i>this</i> taxon name to another taxon name
*/
public int compareToName(TaxonNameBase<?,?> otherName);
+ /**
+ * This method returns als {@link Registration registrations} for the given name.
+ * @return
+ */
+ public Set<Registration> getRegistrations();
+
}
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.Table;
+import org.hibernate.annotations.Type;
import org.hibernate.envers.Audited;
import org.hibernate.search.annotations.Analyze;
import org.hibernate.search.annotations.Analyzer;
import eu.etaxonomy.cdm.model.agent.INomenclaturalAuthor;
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.common.DefinedTermBase;
import eu.etaxonomy.cdm.model.common.IIntextReferenceTarget;
import eu.etaxonomy.cdm.model.common.IParsable;
import eu.etaxonomy.cdm.model.common.IRelated;
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
import eu.etaxonomy.cdm.model.common.RelationshipBase;
+import eu.etaxonomy.cdm.model.common.TermType;
+import eu.etaxonomy.cdm.model.common.TermVocabulary;
import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "TaxonNameBase", propOrder = {
+ "nameType",
"appendedPhrase",
"nomenclaturalMicroReference",
"nomenclaturalReference",
"status",
"descriptions",
"taxonBases",
+ "registrations",
"nameCache",
"genusOrUninomial",
private static final Logger logger = Logger.getLogger(TaxonNameBase.class);
+ /**
+ * The {@link TermType type} of this term. Needs to be the same type in a {@link DefinedTermBase defined term}
+ * and in it's {@link TermVocabulary vocabulary}.
+ */
+ @XmlAttribute(name ="NameType")
+ @Column(name="nameType", length=15)
+ @NotNull
+ @Type(type = "eu.etaxonomy.cdm.hibernate.EnumUserType",
+ parameters = {@org.hibernate.annotations.Parameter(name = "enumClass", value = "eu.etaxonomy.cdm.model.name.NomenclaturalCode")}
+ )
+ @Audited //needed ?
+ private NomenclaturalCode nameType;
+
@XmlElement(name = "FullTitleCache")
@Column(length=800, name="fullTitleCache") //see #1592
@Match(value=MatchMode.CACHE, cacheReplaceMode=ReplaceMode.ALL)
@IndexedEmbedded
private Reference nomenclaturalReference;
+ @XmlElementWrapper(name = "Registrations")
+ @XmlElement(name = "Registration")
+ @XmlIDREF
+ @XmlSchemaType(name = "IDREF")
+ @OneToMany(mappedBy="name", fetch= FetchType.LAZY)
+ @NotNull
+ @IndexedEmbedded(depth=1)
+ private Set<Registration> registrations = new HashSet<>();
+
//****** Non-ViralName attributes ***************************************/
@XmlElement(name = "NameCache")
//see TaxonNameFactory
-// *********************** PARSER STATIC *******************************/
-
-
// ************* CONSTRUCTORS *************/
/**
* Class constructor: creates a new empty taxon name.
+ * @param code
*
* @see #TaxonNameBase(Rank)
* @see #TaxonNameBase(HomotypicalGroup)
super();
setNameCacheStrategy();
}
+ /**
+ * Class constructor: creates a new empty taxon name.
+ * @param code
+ *
+ * @see #TaxonNameBase(Rank)
+ * @see #TaxonNameBase(HomotypicalGroup)
+ * @see #TaxonNameBase(Rank, HomotypicalGroup)
+ */
+ protected TaxonNameBase(NomenclaturalCode type) {
+ super();
+ this.nameType = type;
+ setNameCacheStrategy();
+ }
/**
* Class constructor: creates a new taxon name
* only containing its {@link Rank rank}.
* @see #TaxonNameBase(HomotypicalGroup)
* @see #TaxonNameBase(Rank, HomotypicalGroup)
*/
- protected TaxonNameBase(Rank rank) {
- this(rank, null);
+ protected TaxonNameBase(NomenclaturalCode code, Rank rank) {
+ this(code, rank, null);
}
/**
* Class constructor: creates a new taxon name instance
* @see #TaxonNameBase(Rank)
* @see #TaxonNameBase(Rank, HomotypicalGroup)
*/
- protected TaxonNameBase(HomotypicalGroup homotypicalGroup) {
- this(null, homotypicalGroup);
+ protected TaxonNameBase(NomenclaturalCode type, HomotypicalGroup homotypicalGroup) {
+ this(type, null, homotypicalGroup);
}
/**
* @see #TaxonNameBase(Rank)
* @see #TaxonNameBase(HomotypicalGroup)
*/
- protected TaxonNameBase(Rank rank, HomotypicalGroup homotypicalGroup) {
+ protected TaxonNameBase(NomenclaturalCode type, Rank rank, HomotypicalGroup homotypicalGroup) {
super();
+ this.nameType = type;
this.setRank(rank);
if (homotypicalGroup == null){
homotypicalGroup = new HomotypicalGroup();
* @see eu.etaxonomy.cdm.strategy.cache.name.INameCacheStrategy
* @see eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy
*/
- protected TaxonNameBase(Rank rank, String genusOrUninomial, String infraGenericEpithet, String specificEpithet, String infraSpecificEpithet, TeamOrPersonBase combinationAuthorship, INomenclaturalReference nomenclaturalReference, String nomenclMicroRef, HomotypicalGroup homotypicalGroup) {
- this(rank, homotypicalGroup);
+ protected TaxonNameBase(NomenclaturalCode type, Rank rank, String genusOrUninomial, String infraGenericEpithet, String specificEpithet, String infraSpecificEpithet, TeamOrPersonBase combinationAuthorship, INomenclaturalReference nomenclaturalReference, String nomenclMicroRef, HomotypicalGroup homotypicalGroup) {
+ this(type, rank, homotypicalGroup);
setGenusOrUninomial(genusOrUninomial);
setInfraGenericEpithet (infraGenericEpithet);
setSpecificEpithet(specificEpithet);
* @param toName the taxon name of the target for this new name relationship
* @param type the type of this new name relationship
* @param ruleConsidered the string which specifies the rule on which this name relationship is based
+ * @return
* @see #getRelationsToThisName()
* @see #getNameRelations()
* @see #addRelationshipFromName(TaxonNameBase, NameRelationshipType, String)
* @see #addNameRelationship(NameRelationship)
*/
@Override
- public void addRelationshipToName(TaxonNameBase toName, NameRelationshipType type, String ruleConsidered){
- addRelationshipToName(toName, type, null, null, ruleConsidered);
- // NameRelationship rel = new NameRelationship(toName, this, type, ruleConsidered);
+ public NameRelationship addRelationshipToName(TaxonNameBase toName, NameRelationshipType type, String ruleConsidered){
+ return addRelationshipToName(toName, type, null, null, ruleConsidered);
}
/**
@Override
@Transient
public Set<Taxon> getTaxa(){
- Set<Taxon> result = new HashSet<Taxon>();
+ Set<Taxon> result = new HashSet<>();
for (TaxonBase taxonBase : this.taxonBases){
if (taxonBase instanceof Taxon){
result.add((Taxon)taxonBase);
@Override
@Transient
public Set<Synonym> getSynonyms() {
- Set<Synonym> result = new HashSet<Synonym>();
+ Set<Synonym> result = new HashSet<>();
for (TaxonBase taxonBase : this.taxonBases){
if (taxonBase instanceof Synonym){
result.add((Synonym)taxonBase);
return result;
}
+ //******* REGISTRATION *****************/
+
+ @Override
+ public Set<Registration> getRegistrations() {
+ return this.registrations;
+ }
+
+
// ************* RELATIONSHIPS *****************************/
<parent>
<groupId>eu.etaxonomy</groupId>
<artifactId>cdmlib-parent</artifactId>
- <version>4.7.0-SNAPSHOT</version>
+ <version>4.8.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>cdmlib-services</artifactId>
<name>CDM Services</name>
<description>EDIT CDM library services. The local API and basis for webservices too.</description>
- <packaging>bundle</packaging>
<scm>
<connection>scm:svn:http://dev.e-taxonomy.eu/svn/trunk/cdmlib/cdmlib-service/</connection>
<developerConnection>scm:svn:http://dev.e-taxonomy.eu/svn/trunk/cdmlib/cdmlib-service/</developerConnection>
</scm>
<build>
<plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <version>2.3.6</version>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Export-Package>eu.etaxonomy.cdm.api.service</Export-Package>
- <Bundle-SymbolicName>eu.etaxonomy.cdm.services</Bundle-SymbolicName>
- <Bundle-Activator>eu.etaxonomy.cdm.services.impl.Activator</Bundle-Activator>
- </instructions>
- </configuration>
- </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugins>
</build>
<dependencies>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.osgi.core</artifactId>
- <version>1.0.0</version>
- </dependency>
<dependency>
<groupId>eu.etaxonomy</groupId>
<artifactId>cdmlib-persistence</artifactId>
import eu.etaxonomy.cdm.model.common.ISourceable;\r
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;\r
import eu.etaxonomy.cdm.model.metadata.CdmMetaData;\r
-import eu.etaxonomy.cdm.model.metadata.CdmMetaData.MetaDataPropertyName;\r
+import eu.etaxonomy.cdm.model.metadata.CdmMetaDataPropertyName;\r
import eu.etaxonomy.cdm.persistence.dao.common.ICdmGenericDao;\r
import eu.etaxonomy.cdm.persistence.dao.common.IOriginalSourceDao;\r
import eu.etaxonomy.cdm.persistence.query.OrderHint;\r
\r
@Override\r
public Integer getReferencingObjectsCount(CdmBase referencedCdmBase){\r
- return this.genericDao.getReferencingObjects(referencedCdmBase).size();\r
+ return this.genericDao.getReferencingObjectsCount(referencedCdmBase);\r
}\r
\r
@Override\r
//\r
// referencedCdmBase = (CdmBase)HibernateProxyHelper.deproxy(referencedCdmBase);\r
// Class referencedClass = referencedCdmBase.getClass();\r
- // Set<CdmBase> result = new HashSet<CdmBase>();\r
+ // Set<CdmBase> result = new HashSet<>();\r
// logger.debug("Referenced Class: " + referencedClass.getName());\r
//\r
// for (Class<? extends CdmBase> cdmClass : allCdmClasses){\r
// }\r
//\r
// private Set<Field> getFields(Class clazz){\r
- // Set<Field> result = new HashSet<Field>();\r
+ // Set<Field> result = new HashSet<>();\r
// for (Field field: clazz.getDeclaredFields()){\r
// if (!Modifier.isStatic(field.getModifiers())){\r
// result.add(field);\r
// }\r
//\r
// private Set<CdmBase> getCdmBasesByFieldAndClass(Field field, Class itemClass, Class otherClazz, CdmBase item, boolean isCollection){\r
- // Set<CdmBase> result = new HashSet<CdmBase>();\r
+ // Set<CdmBase> result = new HashSet<>();\r
// if (isCollection){\r
// result.addAll(genericDao.getCdmBasesWithItemInCollection(itemClass, otherClazz, field.getName(), item));\r
// }else{\r
}\r
\r
@Override\r
- public Map<MetaDataPropertyName, CdmMetaData> getCdmMetaData() {\r
- Map<MetaDataPropertyName, CdmMetaData> result = new HashMap<MetaDataPropertyName, CdmMetaData>();\r
+ public Map<CdmMetaDataPropertyName, CdmMetaData> getCdmMetaData() {\r
+ Map<CdmMetaDataPropertyName, CdmMetaData> result = new HashMap<>();\r
List<CdmMetaData> metaDataList = genericDao.getMetaData();\r
for (CdmMetaData metaData : metaDataList){\r
- MetaDataPropertyName propertyName = metaData.getPropertyName();\r
+ CdmMetaDataPropertyName propertyName = metaData.getPropertyName();\r
result.put(propertyName, metaData);\r
}\r
return result;\r
return delete(name.getUuid());
}
- /* (non-Javadoc)
- * @see eu.etaxonomy.cdm.api.service.INameService#delete(eu.etaxonomy.cdm.model.name.TaxonNameBase, eu.etaxonomy.cdm.api.service.NameDeletionConfigurator)
- */
@Override
@Transactional(readOnly = false)
- public DeleteResult delete(UUID nameUUID, NameDeletionConfigurator config) {
- DeleteResult result = new DeleteResult();
- TaxonNameBase name = dao.load(nameUUID);
+ public DeleteResult delete(TaxonNameBase name, NameDeletionConfigurator config) {
+ DeleteResult result = new DeleteResult();
- if (name == null){
- result.setAbort();
+
+ if (name == null){
+ result.setAbort();
return result;
}
- try{
- result = this.isDeletable(name.getUuid(), config);
+ try{
+ result = this.isDeletable(name, config);
}catch(Exception e){
- result.addException(e);
- result.setError();
- return result;
+ result.addException(e);
+ result.setError();
+ return result;
}
if (result.isOk()){
//remove references to this name
- removeNameRelationshipsByDeleteConfig(name, config);
+ removeNameRelationshipsByDeleteConfig(name, config);
//remove name from homotypical group
HomotypicalGroup homotypicalGroup = name.getHomotypicalGroup();
}
//all type designation relationships are removed as they belong to the name
- deleteTypeDesignation(name, null);
- // //type designations
- // if (! name.getTypeDesignations().isEmpty()){
- // String message = "Name can't be deleted as it has types. Remove types prior to deletion.";
- // throw new ReferrencedObjectUndeletableException(message);
- // }
+ deleteTypeDesignation(name, null);
+ // //type designations
+ // if (! name.getTypeDesignations().isEmpty()){
+ // String message = "Name can't be deleted as it has types. Remove types prior to deletion.";
+ // throw new ReferrencedObjectUndeletableException(message);
+ // }
- try{
- UUID nameUuid = dao.delete(name);
+ try{
+ UUID nameUuid = dao.delete(name);
- }catch(Exception e){
- result.addException(e);
- result.setError();
- }
- return result;
+ }catch(Exception e){
+ result.addException(e);
+ result.setError();
+ }
+ return result;
}
return result;
}
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.cdm.api.service.INameService#delete(eu.etaxonomy.cdm.model.name.TaxonNameBase, eu.etaxonomy.cdm.api.service.NameDeletionConfigurator)
+ */
+ @Override
+ @Transactional(readOnly = false)
+ public DeleteResult delete(UUID nameUUID, NameDeletionConfigurator config) {
+
+ TaxonNameBase name = dao.load(nameUUID);
+ return delete(name, config);
+ }
+
@Override
public DeleteResult deleteTypeDesignation(TaxonNameBase name, TypeDesignationBase typeDesignation){
if(typeDesignation!=null && typeDesignation.getId()!=0){
return referencedEntityDao.saveAll(referencedEntityCollection);
}
- /**
- * TODO candidate for harmonization
- * new name getNames
- */
- public List<TaxonNameBase> getAllNames(int limit, int start){
- return dao.list(limit, start);
- }
-
/**
* TODO candidate for harmonization
* new name getNomenclaturalStatus
return taggedName;
}
- @Override
- public DeleteResult isDeletable(UUID nameUUID, DeleteConfiguratorBase config){
- DeleteResult result = new DeleteResult();
- TaxonNameBase name = this.load(nameUUID);
- NameDeletionConfigurator nameConfig = null;
- if (config instanceof NameDeletionConfigurator){
- nameConfig = (NameDeletionConfigurator) config;
- }else{
- result.addException(new Exception("The delete configurator should be of the type NameDeletionConfigurator."));
- result.setError();
- return result;
- }
- if (!name.getNameRelations().isEmpty() && !nameConfig.isRemoveAllNameRelationships()){
- HomotypicalGroup homotypicalGroup = HibernateProxyHelper.deproxy(name.getHomotypicalGroup(), HomotypicalGroup.class);
+ public DeleteResult isDeletable(TaxonNameBase name, DeleteConfiguratorBase config){
+ DeleteResult result = new DeleteResult();
+
+ NameDeletionConfigurator nameConfig = null;
+ if (config instanceof NameDeletionConfigurator){
+ nameConfig = (NameDeletionConfigurator) config;
+ }else{
+ result.addException(new Exception("The delete configurator should be of the type NameDeletionConfigurator."));
+ result.setError();
+ return result;
+ }
+
+ if (!name.getNameRelations().isEmpty() && !nameConfig.isRemoveAllNameRelationships()){
+ HomotypicalGroup homotypicalGroup = HibernateProxyHelper.deproxy(name.getHomotypicalGroup(), HomotypicalGroup.class);
- if (!nameConfig.isIgnoreIsBasionymFor() && homotypicalGroup.getBasionyms().contains(name)){
- result.addException(new Exception( "Name can't be deleted as it is a basionym."));
- result.setAbort();
+ if (!nameConfig.isIgnoreIsBasionymFor() && homotypicalGroup.getBasionyms().contains(name)){
+ result.addException(new Exception( "Name can't be deleted as it is a basionym."));
+ result.setAbort();
}
if (!nameConfig.isIgnoreHasBasionym() && (name.getBasionyms().size()>0)){
- result.addException(new Exception( "Name can't be deleted as it has a basionym."));
- result.setAbort();
+ result.addException(new Exception( "Name can't be deleted as it has a basionym."));
+ result.setAbort();
}
Set<NameRelationship> relationships = name.getNameRelations();
for (NameRelationship rel: relationships){
- if (!rel.getType().equals(NameRelationshipType.BASIONYM())){
- result.addException(new Exception("Name can't be deleted as it is used in name relationship(s). Remove name relationships prior to deletion."));
- result.setAbort();
- break;
- }
+ if (!rel.getType().equals(NameRelationshipType.BASIONYM())){
+ result.addException(new Exception("Name can't be deleted as it is used in name relationship(s). Remove name relationships prior to deletion."));
+ result.setAbort();
+ break;
+ }
}
}
//concepts
if (! name.getTaxonBases().isEmpty()){
- result.addException(new Exception("Name can't be deleted as it is used in concept(s). Remove or change concept prior to deletion."));
- result.setAbort();
+ result.addException(new Exception("Name can't be deleted as it is used in concept(s). Remove or change concept prior to deletion."));
+ result.setAbort();
}
//hybrid relationships
Set<HybridRelationship> parentHybridRelations = nvn.getHybridParentRelations();
//Hibernate.initialize(parentHybridRelations);
if (! parentHybridRelations.isEmpty()){
- result.addException(new Exception("Name can't be deleted as it is a parent in (a) hybrid relationship(s). Remove hybrid relationships prior to deletion."));
- result.setAbort();
+ result.addException(new Exception("Name can't be deleted as it is a parent in (a) hybrid relationship(s). Remove hybrid relationships prior to deletion."));
+ result.setAbort();
}
}
- Set<CdmBase> referencingObjects = genericDao.getReferencingObjectsForDeletion(name);
+ Set<CdmBase> referencingObjects = genericDao.getReferencingObjectsForDeletion(name);
for (CdmBase referencingObject : referencingObjects){
//DerivedUnit?.storedUnder
if (referencingObject.isInstanceOf(DerivedUnit.class)){
result.addException(new Exception(message));
result.setAbort();
}
- return result;
+ return result;
}
+
+ @Override
+ public DeleteResult isDeletable(UUID nameUUID, DeleteConfiguratorBase config){
+ TaxonNameBase name = this.load(nameUUID);
+ return isDeletable(name, config);
+ }
+
@Override
@Transactional(readOnly = true)
public UpdateResult setAsGroupsBasionym(UUID nameUuid) {