Revision d9f134f9
Added by Katja Luther about 8 years ago
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/taxon/TaxonNodeByNameComparator.java | ||
---|---|---|
13 | 13 |
import java.util.StringTokenizer; |
14 | 14 |
|
15 | 15 |
import org.apache.log4j.Logger; |
16 |
import org.springframework.stereotype.Component; |
|
17 | 16 |
|
18 | 17 |
import eu.etaxonomy.cdm.common.AbstractStringComparator; |
19 | 18 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
... | ... | |
26 | 25 |
* @date 24.06.2009 |
27 | 26 |
* |
28 | 27 |
*/ |
29 |
@Component |
|
28 |
//@Component
|
|
30 | 29 |
public class TaxonNodeByNameComparator extends AbstractStringComparator<TaxonNode> implements Comparator<TaxonNode>, ITaxonNodeComparator<TaxonNode> { |
31 | 30 |
|
32 | 31 |
private static final String HYBRID_SIGN = "\u00D7"; |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/media/MediaRepresentationDaoImpl.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2008 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
*/ |
|
6 |
|
|
7 |
package eu.etaxonomy.cdm.persistence.dao.hibernate.media; |
|
8 |
|
|
9 |
import org.springframework.stereotype.Repository; |
|
10 |
|
|
11 |
import eu.etaxonomy.cdm.model.media.MediaRepresentation; |
|
12 |
import eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmEntityDaoBase; |
|
13 |
import eu.etaxonomy.cdm.persistence.dao.media.IMediaRepresentationDao; |
|
14 |
|
|
15 |
/** |
|
16 |
* @author a.babadshanjan |
|
17 |
* @created 08.09.2008 |
|
18 |
*/ |
|
19 |
@Repository |
|
20 |
public class MediaRepresentationDaoImpl extends CdmEntityDaoBase<MediaRepresentation> |
|
21 |
implements IMediaRepresentationDao { |
|
22 |
|
|
23 |
public MediaRepresentationDaoImpl() { |
|
24 |
super(MediaRepresentation.class); |
|
25 |
} |
|
26 |
} |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/media/MediaRepresentationHibernateImpl.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2008 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
*/ |
|
6 |
|
|
7 |
package eu.etaxonomy.cdm.persistence.dao.hibernate.media; |
|
8 |
|
|
9 |
import org.springframework.stereotype.Repository; |
|
10 |
|
|
11 |
import eu.etaxonomy.cdm.model.media.MediaRepresentation; |
|
12 |
import eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmEntityDaoBase; |
|
13 |
import eu.etaxonomy.cdm.persistence.dao.media.IMediaRepresentationDao; |
|
14 |
|
|
15 |
/** |
|
16 |
* @author a.babadshanjan |
|
17 |
* @created 08.09.2008 |
|
18 |
*/ |
|
19 |
@Repository |
|
20 |
public class MediaRepresentationHibernateImpl extends CdmEntityDaoBase<MediaRepresentation> |
|
21 |
implements IMediaRepresentationDao { |
|
22 |
|
|
23 |
public MediaRepresentationHibernateImpl() { |
|
24 |
super(MediaRepresentation.class); |
|
25 |
} |
|
26 |
} |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/media/MediaRepresentationPartDaoImpl.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2008 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
*/ |
|
6 |
|
|
7 |
package eu.etaxonomy.cdm.persistence.dao.hibernate.media; |
|
8 |
|
|
9 |
import org.springframework.stereotype.Repository; |
|
10 |
|
|
11 |
import eu.etaxonomy.cdm.model.media.MediaRepresentationPart; |
|
12 |
import eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmEntityDaoBase; |
|
13 |
import eu.etaxonomy.cdm.persistence.dao.media.IMediaRepresentationPartDao; |
|
14 |
|
|
15 |
/** |
|
16 |
* @author a.babadshanjan |
|
17 |
* @created 08.09.2008 |
|
18 |
*/ |
|
19 |
@Repository |
|
20 |
public class MediaRepresentationPartDaoImpl extends CdmEntityDaoBase<MediaRepresentationPart> |
|
21 |
implements IMediaRepresentationPartDao { |
|
22 |
|
|
23 |
public MediaRepresentationPartDaoImpl() { |
|
24 |
super(MediaRepresentationPart.class); |
|
25 |
} |
|
26 |
} |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/media/MediaRepresentationPartHibernateImpl.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2008 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
*/ |
|
6 |
|
|
7 |
package eu.etaxonomy.cdm.persistence.dao.hibernate.media; |
|
8 |
|
|
9 |
import org.springframework.stereotype.Repository; |
|
10 |
|
|
11 |
import eu.etaxonomy.cdm.model.media.MediaRepresentationPart; |
|
12 |
import eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmEntityDaoBase; |
|
13 |
import eu.etaxonomy.cdm.persistence.dao.media.IMediaRepresentationPartDao; |
|
14 |
|
|
15 |
/** |
|
16 |
* @author a.babadshanjan |
|
17 |
* @created 08.09.2008 |
|
18 |
*/ |
|
19 |
@Repository |
|
20 |
public class MediaRepresentationPartHibernateImpl extends CdmEntityDaoBase<MediaRepresentationPart> |
|
21 |
implements IMediaRepresentationPartDao { |
|
22 |
|
|
23 |
public MediaRepresentationPartHibernateImpl() { |
|
24 |
super(MediaRepresentationPart.class); |
|
25 |
} |
|
26 |
} |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IMediaService.java | ||
---|---|---|
1 | 1 |
// $Id$ |
2 | 2 |
/** |
3 | 3 |
* Copyright (C) 2007 EDIT |
4 |
* European Distributed Institute of Taxonomy
|
|
4 |
* European Distributed Institute of Taxonomy |
|
5 | 5 |
* http://www.e-taxonomy.eu |
6 |
*
|
|
6 |
* |
|
7 | 7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
8 | 8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
9 | 9 |
*/ |
... | ... | |
12 | 12 |
|
13 | 13 |
import java.util.List; |
14 | 14 |
import java.util.Set; |
15 |
import java.util.UUID; |
|
15 | 16 |
|
17 |
import eu.etaxonomy.cdm.api.service.config.MediaDeletionConfigurator; |
|
16 | 18 |
import eu.etaxonomy.cdm.api.service.pager.Pager; |
17 | 19 |
import eu.etaxonomy.cdm.model.description.MediaKey; |
18 | 20 |
import eu.etaxonomy.cdm.model.location.NamedArea; |
... | ... | |
26 | 28 |
|
27 | 29 |
/** |
28 | 30 |
* Return a List of MediaKeys, optionally filtered by the parameters passed. |
29 |
*
|
|
31 |
* |
|
30 | 32 |
* @param taxonomicScope a Set of Taxon instances that define the taxonomic scope of the key (can be null) |
31 | 33 |
* @param geoScopes a Set of NamedArea instances that define the geospatial scope of the key (can be null) |
32 | 34 |
* @param pageSize The maximum number of keys returned (can be null for all keys) |
... | ... | |
35 | 37 |
* @return a Pager containing MediaKey instances |
36 | 38 |
*/ |
37 | 39 |
public Pager<MediaKey> getMediaKeys(Set<Taxon> taxonomicScope, Set<NamedArea> geoScopes, Integer pageSize, Integer pageNumber, List<String> propertyPaths); |
38 |
|
|
40 |
|
|
39 | 41 |
/** |
40 | 42 |
* Return a Pager of rights belonging to this object |
41 |
*
|
|
43 |
* |
|
42 | 44 |
* @param t The media object |
43 | 45 |
* @param pageSize The maximum number of rights returned (can be null for all rights) |
44 | 46 |
* @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based) |
45 | 47 |
* @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)} |
46 | 48 |
* @return a Pager of Rights entities |
47 | 49 |
*/ |
50 |
@Override |
|
48 | 51 |
public Pager<Rights> getRights(Media t, Integer pageSize, Integer pageNumber, List<String> propertyPaths); |
49 |
|
|
52 |
|
|
50 | 53 |
/** |
51 | 54 |
* Returns a Paged List of Media instances where the default field matches the String queryString (as interpreted by the Lucene QueryParser) |
52 |
*
|
|
55 |
* |
|
53 | 56 |
* @param clazz filter the results by class (or pass null to return all Media instances) |
54 | 57 |
* @param queryString |
55 | 58 |
* @param pageSize The maximum number of media returned (can be null for all matching media) |
... | ... | |
62 | 65 |
* @return a Pager Media instances |
63 | 66 |
* @see <a href="http://lucene.apache.org/java/2_4_0/queryparsersyntax.html">Apache Lucene - Query Parser Syntax</a> |
64 | 67 |
*/ |
65 |
public Pager<Media> search(Class<? extends Media> clazz, String queryString, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths); |
|
68 |
@Override |
|
69 |
public Pager<Media> search(Class<? extends Media> clazz, String queryString, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths); |
|
70 |
|
|
71 |
|
|
72 |
public DeleteResult delete(UUID mediaUuid, MediaDeletionConfigurator config); |
|
66 | 73 |
} |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/MediaServiceImpl.java | ||
---|---|---|
1 | 1 |
// $Id$ |
2 | 2 |
/** |
3 | 3 |
* Copyright (C) 2007 EDIT |
4 |
* European Distributed Institute of Taxonomy
|
|
4 |
* European Distributed Institute of Taxonomy |
|
5 | 5 |
* http://www.e-taxonomy.eu |
6 |
*
|
|
6 |
* |
|
7 | 7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
8 | 8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
9 | 9 |
*/ |
... | ... | |
13 | 13 |
import java.util.ArrayList; |
14 | 14 |
import java.util.List; |
15 | 15 |
import java.util.Set; |
16 |
import java.util.UUID; |
|
16 | 17 |
|
17 | 18 |
import org.springframework.beans.factory.annotation.Autowired; |
18 | 19 |
import org.springframework.stereotype.Service; |
19 | 20 |
import org.springframework.transaction.annotation.Transactional; |
20 | 21 |
|
22 |
import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase; |
|
23 |
import eu.etaxonomy.cdm.api.service.config.MediaDeletionConfigurator; |
|
24 |
import eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException; |
|
21 | 25 |
import eu.etaxonomy.cdm.api.service.pager.Pager; |
22 | 26 |
import eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl; |
23 | 27 |
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor; |
28 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
|
29 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
30 |
import eu.etaxonomy.cdm.model.description.DescriptionBase; |
|
24 | 31 |
import eu.etaxonomy.cdm.model.description.MediaKey; |
32 |
import eu.etaxonomy.cdm.model.description.SpecimenDescription; |
|
33 |
import eu.etaxonomy.cdm.model.description.TaxonDescription; |
|
34 |
import eu.etaxonomy.cdm.model.description.TextData; |
|
25 | 35 |
import eu.etaxonomy.cdm.model.location.NamedArea; |
26 | 36 |
import eu.etaxonomy.cdm.model.media.Media; |
27 | 37 |
import eu.etaxonomy.cdm.model.media.Rights; |
... | ... | |
33 | 43 |
@Transactional(readOnly=true) |
34 | 44 |
public class MediaServiceImpl extends IdentifiableServiceBase<Media,IMediaDao> implements IMediaService { |
35 | 45 |
|
36 |
@Autowired |
|
46 |
@Override |
|
47 |
@Autowired |
|
37 | 48 |
protected void setDao(IMediaDao dao) { |
38 | 49 |
this.dao = dao; |
39 | 50 |
} |
40 | 51 |
|
41 |
public Pager<MediaKey> getMediaKeys(Set<Taxon> taxonomicScope, Set<NamedArea> geoScopes, Integer pageSize, Integer pageNumber, List<String> propertyPaths) { |
|
52 |
@Autowired |
|
53 |
private IDescriptionService descriptionService; |
|
54 |
|
|
55 |
@Override |
|
56 |
public Pager<MediaKey> getMediaKeys(Set<Taxon> taxonomicScope, Set<NamedArea> geoScopes, Integer pageSize, Integer pageNumber, List<String> propertyPaths) { |
|
42 | 57 |
Integer numberOfResults = dao.countMediaKeys(taxonomicScope, geoScopes); |
43 |
|
|
58 |
|
|
44 | 59 |
List<MediaKey> results = new ArrayList<MediaKey>(); |
45 | 60 |
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize) |
46 |
results = dao.getMediaKeys(taxonomicScope, geoScopes, pageSize, pageNumber, propertyPaths);
|
|
61 |
results = dao.getMediaKeys(taxonomicScope, geoScopes, pageSize, pageNumber, propertyPaths); |
|
47 | 62 |
} |
48 |
|
|
63 |
|
|
49 | 64 |
return new DefaultPagerImpl<MediaKey>(pageNumber, numberOfResults, pageSize, results); |
50 | 65 |
} |
51 |
|
|
52 |
public Pager<Rights> getRights(Media t, Integer pageSize, Integer pageNumber, List<String> propertyPaths) { |
|
66 |
|
|
67 |
@Override |
|
68 |
public Pager<Rights> getRights(Media t, Integer pageSize, Integer pageNumber, List<String> propertyPaths) { |
|
53 | 69 |
Integer numberOfResults = dao.countRights(t); |
54 |
|
|
70 |
|
|
55 | 71 |
List<Rights> results = new ArrayList<Rights>(); |
56 | 72 |
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize) |
57 |
results = dao.getRights(t, pageSize, pageNumber,propertyPaths);
|
|
73 |
results = dao.getRights(t, pageSize, pageNumber,propertyPaths); |
|
58 | 74 |
} |
59 |
|
|
75 |
|
|
60 | 76 |
return new DefaultPagerImpl<Rights>(pageNumber, numberOfResults, pageSize, results); |
61 | 77 |
} |
62 | 78 |
|
... | ... | |
72 | 88 |
} |
73 | 89 |
super.updateTitleCacheImpl(clazz, stepSize, cacheStrategy, monitor); |
74 | 90 |
} |
91 |
|
|
92 |
/* (non-Javadoc) |
|
93 |
* @see eu.etaxonomy.cdm.api.service.IMediaService#delete(java.util.UUID, eu.etaxonomy.cdm.api.service.config.MediaDeletionConfigurator) |
|
94 |
*/ |
|
95 |
@Override |
|
96 |
public DeleteResult delete(UUID mediaUuid, MediaDeletionConfigurator config) { |
|
97 |
DeleteResult result = new DeleteResult(); |
|
98 |
Media media = this.load(mediaUuid); |
|
99 |
|
|
100 |
result = isDeletable(media, config); |
|
101 |
|
|
102 |
if (result.isOk()){ |
|
103 |
dao.delete(media); |
|
104 |
} |
|
105 |
return result; |
|
106 |
} |
|
107 |
|
|
108 |
@Override |
|
109 |
public DeleteResult isDeletable(Media media, DeleteConfiguratorBase config){ |
|
110 |
DeleteResult result = new DeleteResult(); |
|
111 |
Set<CdmBase> references = commonService.getReferencingObjectsForDeletion(media); |
|
112 |
String message = null; |
|
113 |
for (CdmBase ref: references){ |
|
114 |
if (ref instanceof TextData){ |
|
115 |
TextData textData = HibernateProxyHelper.deproxy(ref, TextData.class); |
|
116 |
DescriptionBase description = textData.getInDescription(); |
|
117 |
if (description.isImageGallery()){ |
|
118 |
if (description instanceof TaxonDescription){ |
|
119 |
TaxonDescription desc = HibernateProxyHelper.deproxy(description, TaxonDescription.class); |
|
120 |
if (desc.getTaxon() == null){ |
|
121 |
continue; |
|
122 |
} else{ |
|
123 |
message = "The media can't be deleted because it is referenced by a taxon. ("+desc.getTaxon().getTitleCache()+")"; |
|
124 |
} |
|
125 |
|
|
126 |
} else if (description instanceof SpecimenDescription){ |
|
127 |
SpecimenDescription desc = HibernateProxyHelper.deproxy(description, SpecimenDescription.class); |
|
128 |
if (desc.getDescribedSpecimenOrObservation() == null){ |
|
129 |
continue; |
|
130 |
} else{ |
|
131 |
message = "The media can't be deleted because it is referenced by a specimen or observation. ("+desc.getDescribedSpecimenOrObservation().getTitleCache()+")"; |
|
132 |
} |
|
133 |
} |
|
134 |
} |
|
135 |
} |
|
136 |
if (message != null){ |
|
137 |
result.addException(new ReferencedObjectUndeletableException(message)); |
|
138 |
result.addRelatedObject(ref); |
|
139 |
result.setAbort(); |
|
140 |
} |
|
141 |
|
|
142 |
} |
|
143 |
|
|
144 |
|
|
145 |
return result; |
|
146 |
|
|
147 |
} |
|
75 | 148 |
} |
Also available in: Unified diff
TaxonNodeByNameComparator is not a component anymore and add configurable delete method for media