Revision a80ca382
minor
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/INameService.java | ||
---|---|---|
474 | 474 |
|
475 | 475 |
public List<HashMap<String, String>> getNameRecords(); |
476 | 476 |
|
477 |
/** |
|
478 |
* @param name |
|
479 |
* @param config |
|
480 |
* @return |
|
481 |
*/ |
|
482 |
DeleteResult delete(TaxonNameBase name, NameDeletionConfigurator config); |
|
483 |
|
|
477 | 484 |
|
478 | 485 |
} |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/NameServiceImpl.java | ||
---|---|---|
135 | 135 |
return delete(name.getUuid()); |
136 | 136 |
} |
137 | 137 |
|
138 |
/* (non-Javadoc) |
|
139 |
* @see eu.etaxonomy.cdm.api.service.INameService#delete(eu.etaxonomy.cdm.model.name.TaxonNameBase, eu.etaxonomy.cdm.api.service.NameDeletionConfigurator) |
|
140 |
*/ |
|
141 | 138 |
@Override |
142 | 139 |
@Transactional(readOnly = false) |
143 |
public DeleteResult delete(UUID nameUUID, NameDeletionConfigurator config) { |
|
144 |
DeleteResult result = new DeleteResult(); |
|
145 |
TaxonNameBase name = dao.load(nameUUID); |
|
140 |
public DeleteResult delete(TaxonNameBase name, NameDeletionConfigurator config) { |
|
141 |
DeleteResult result = new DeleteResult(); |
|
146 | 142 |
|
147 |
if (name == null){ |
|
148 |
result.setAbort(); |
|
143 |
|
|
144 |
if (name == null){ |
|
145 |
result.setAbort(); |
|
149 | 146 |
return result; |
150 | 147 |
} |
151 | 148 |
|
152 |
try{
|
|
153 |
result = this.isDeletable(name.getUuid(), config);
|
|
149 |
try{
|
|
150 |
result = this.isDeletable(name, config);
|
|
154 | 151 |
}catch(Exception e){ |
155 |
result.addException(e);
|
|
156 |
result.setError();
|
|
157 |
return result;
|
|
152 |
result.addException(e);
|
|
153 |
result.setError();
|
|
154 |
return result;
|
|
158 | 155 |
} |
159 | 156 |
if (result.isOk()){ |
160 | 157 |
//remove references to this name |
161 |
removeNameRelationshipsByDeleteConfig(name, config);
|
|
158 |
removeNameRelationshipsByDeleteConfig(name, config);
|
|
162 | 159 |
|
163 | 160 |
//remove name from homotypical group |
164 | 161 |
HomotypicalGroup homotypicalGroup = name.getHomotypicalGroup(); |
... | ... | |
167 | 164 |
} |
168 | 165 |
|
169 | 166 |
//all type designation relationships are removed as they belong to the name |
170 |
deleteTypeDesignation(name, null);
|
|
171 |
// //type designations
|
|
172 |
// if (! name.getTypeDesignations().isEmpty()){
|
|
173 |
// String message = "Name can't be deleted as it has types. Remove types prior to deletion.";
|
|
174 |
// throw new ReferrencedObjectUndeletableException(message);
|
|
175 |
// }
|
|
167 |
deleteTypeDesignation(name, null);
|
|
168 |
// //type designations
|
|
169 |
// if (! name.getTypeDesignations().isEmpty()){
|
|
170 |
// String message = "Name can't be deleted as it has types. Remove types prior to deletion.";
|
|
171 |
// throw new ReferrencedObjectUndeletableException(message);
|
|
172 |
// }
|
|
176 | 173 |
|
177 | 174 |
|
178 |
try{
|
|
179 |
UUID nameUuid = dao.delete(name);
|
|
175 |
try{
|
|
176 |
UUID nameUuid = dao.delete(name);
|
|
180 | 177 |
|
181 |
}catch(Exception e){
|
|
182 |
result.addException(e);
|
|
183 |
result.setError();
|
|
184 |
}
|
|
185 |
return result;
|
|
178 |
}catch(Exception e){
|
|
179 |
result.addException(e);
|
|
180 |
result.setError();
|
|
181 |
}
|
|
182 |
return result;
|
|
186 | 183 |
} |
187 | 184 |
|
188 | 185 |
return result; |
189 | 186 |
} |
190 | 187 |
|
188 |
|
|
189 |
/* (non-Javadoc) |
|
190 |
* @see eu.etaxonomy.cdm.api.service.INameService#delete(eu.etaxonomy.cdm.model.name.TaxonNameBase, eu.etaxonomy.cdm.api.service.NameDeletionConfigurator) |
|
191 |
*/ |
|
192 |
@Override |
|
193 |
@Transactional(readOnly = false) |
|
194 |
public DeleteResult delete(UUID nameUUID, NameDeletionConfigurator config) { |
|
195 |
|
|
196 |
TaxonNameBase name = dao.load(nameUUID); |
|
197 |
return delete(name, config); |
|
198 |
} |
|
199 |
|
|
191 | 200 |
@Override |
192 | 201 |
public DeleteResult deleteTypeDesignation(TaxonNameBase name, TypeDesignationBase typeDesignation){ |
193 | 202 |
if(typeDesignation!=null && typeDesignation.getId()!=0){ |
... | ... | |
817 | 826 |
return taggedName; |
818 | 827 |
} |
819 | 828 |
|
820 |
@Override |
|
821 |
public DeleteResult isDeletable(UUID nameUUID, DeleteConfiguratorBase config){ |
|
822 |
DeleteResult result = new DeleteResult(); |
|
823 |
TaxonNameBase name = this.load(nameUUID); |
|
824 |
NameDeletionConfigurator nameConfig = null; |
|
825 |
if (config instanceof NameDeletionConfigurator){ |
|
826 |
nameConfig = (NameDeletionConfigurator) config; |
|
827 |
}else{ |
|
828 |
result.addException(new Exception("The delete configurator should be of the type NameDeletionConfigurator.")); |
|
829 |
result.setError(); |
|
830 |
return result; |
|
831 |
} |
|
832 | 829 |
|
833 |
if (!name.getNameRelations().isEmpty() && !nameConfig.isRemoveAllNameRelationships()){ |
|
834 |
HomotypicalGroup homotypicalGroup = HibernateProxyHelper.deproxy(name.getHomotypicalGroup(), HomotypicalGroup.class); |
|
830 |
public DeleteResult isDeletable(TaxonNameBase name, DeleteConfiguratorBase config){ |
|
831 |
DeleteResult result = new DeleteResult(); |
|
832 |
|
|
833 |
NameDeletionConfigurator nameConfig = null; |
|
834 |
if (config instanceof NameDeletionConfigurator){ |
|
835 |
nameConfig = (NameDeletionConfigurator) config; |
|
836 |
}else{ |
|
837 |
result.addException(new Exception("The delete configurator should be of the type NameDeletionConfigurator.")); |
|
838 |
result.setError(); |
|
839 |
return result; |
|
840 |
} |
|
841 |
|
|
842 |
if (!name.getNameRelations().isEmpty() && !nameConfig.isRemoveAllNameRelationships()){ |
|
843 |
HomotypicalGroup homotypicalGroup = HibernateProxyHelper.deproxy(name.getHomotypicalGroup(), HomotypicalGroup.class); |
|
835 | 844 |
|
836 |
if (!nameConfig.isIgnoreIsBasionymFor() && homotypicalGroup.getBasionyms().contains(name)){
|
|
837 |
result.addException(new Exception( "Name can't be deleted as it is a basionym."));
|
|
838 |
result.setAbort();
|
|
845 |
if (!nameConfig.isIgnoreIsBasionymFor() && homotypicalGroup.getBasionyms().contains(name)){
|
|
846 |
result.addException(new Exception( "Name can't be deleted as it is a basionym."));
|
|
847 |
result.setAbort();
|
|
839 | 848 |
} |
840 | 849 |
if (!nameConfig.isIgnoreHasBasionym() && (name.getBasionyms().size()>0)){ |
841 |
result.addException(new Exception( "Name can't be deleted as it has a basionym."));
|
|
842 |
result.setAbort();
|
|
850 |
result.addException(new Exception( "Name can't be deleted as it has a basionym."));
|
|
851 |
result.setAbort();
|
|
843 | 852 |
} |
844 | 853 |
Set<NameRelationship> relationships = name.getNameRelations(); |
845 | 854 |
for (NameRelationship rel: relationships){ |
846 |
if (!rel.getType().equals(NameRelationshipType.BASIONYM())){
|
|
847 |
result.addException(new Exception("Name can't be deleted as it is used in name relationship(s). Remove name relationships prior to deletion."));
|
|
848 |
result.setAbort();
|
|
849 |
break;
|
|
850 |
}
|
|
855 |
if (!rel.getType().equals(NameRelationshipType.BASIONYM())){
|
|
856 |
result.addException(new Exception("Name can't be deleted as it is used in name relationship(s). Remove name relationships prior to deletion."));
|
|
857 |
result.setAbort();
|
|
858 |
break;
|
|
859 |
}
|
|
851 | 860 |
} |
852 | 861 |
} |
853 | 862 |
|
854 | 863 |
//concepts |
855 | 864 |
if (! name.getTaxonBases().isEmpty()){ |
856 |
result.addException(new Exception("Name can't be deleted as it is used in concept(s). Remove or change concept prior to deletion."));
|
|
857 |
result.setAbort();
|
|
865 |
result.addException(new Exception("Name can't be deleted as it is used in concept(s). Remove or change concept prior to deletion."));
|
|
866 |
result.setAbort();
|
|
858 | 867 |
} |
859 | 868 |
|
860 | 869 |
//hybrid relationships |
... | ... | |
863 | 872 |
Set<HybridRelationship> parentHybridRelations = nvn.getHybridParentRelations(); |
864 | 873 |
//Hibernate.initialize(parentHybridRelations); |
865 | 874 |
if (! parentHybridRelations.isEmpty()){ |
866 |
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."));
|
|
867 |
result.setAbort();
|
|
875 |
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."));
|
|
876 |
result.setAbort();
|
|
868 | 877 |
} |
869 | 878 |
} |
870 |
Set<CdmBase> referencingObjects = genericDao.getReferencingObjectsForDeletion(name);
|
|
879 |
Set<CdmBase> referencingObjects = genericDao.getReferencingObjectsForDeletion(name);
|
|
871 | 880 |
for (CdmBase referencingObject : referencingObjects){ |
872 | 881 |
//DerivedUnit?.storedUnder |
873 | 882 |
if (referencingObject.isInstanceOf(DerivedUnit.class)){ |
... | ... | |
917 | 926 |
result.addException(new Exception(message)); |
918 | 927 |
result.setAbort(); |
919 | 928 |
} |
920 |
return result;
|
|
929 |
return result;
|
|
921 | 930 |
|
922 | 931 |
} |
923 | 932 |
|
933 |
|
|
934 |
@Override |
|
935 |
public DeleteResult isDeletable(UUID nameUUID, DeleteConfiguratorBase config){ |
|
936 |
TaxonNameBase name = this.load(nameUUID); |
|
937 |
return isDeletable(name, config); |
|
938 |
} |
|
939 |
|
|
924 | 940 |
@Override |
925 | 941 |
@Transactional(readOnly = true) |
926 | 942 |
public UpdateResult setAsGroupsBasionym(UUID nameUuid) { |
Also available in: Unified diff