2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.bulkeditor
.input
;
11 import java
.util
.ArrayList
;
12 import java
.util
.Arrays
;
13 import java
.util
.List
;
14 import java
.util
.UUID
;
16 import eu
.etaxonomy
.cdm
.api
.service
.IReferenceService
;
17 import eu
.etaxonomy
.cdm
.api
.service
.config
.DeleteConfiguratorBase
;
18 import eu
.etaxonomy
.cdm
.api
.service
.config
.IIdentifiableEntityServiceConfigurator
;
19 import eu
.etaxonomy
.cdm
.api
.service
.exception
.ReferencedObjectUndeletableException
;
20 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
21 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
22 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.IEntityCreator
;
23 import eu
.etaxonomy
.taxeditor
.bulkeditor
.IBulkEditorSortProvider
;
24 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.entitycreator
.ReferenceCreator
;
25 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.sortprovider
.IdentifiableEntitySortProvider
;
26 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.sortprovider
.ReferenceSortProvider
;
27 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
33 public class ReferenceEditorInput
extends AbstractBulkEditorInput
<Reference
> {
35 private static final long serialVersionUID
= 3806243517765126749L;
37 public static final String ID
= "bulkeditor.input.reference";
39 private static final String PROPERTY_NOMENCLATURAL_CACHE
= "Nomencl. Cache";
40 private static final String PROPERTY_PROTECT_NOMENCLATURAL_CACHE
= "Protect Nomencl. Cache";
41 private static final String PROPERTY_TITLE
= "Title";
42 private static final String PROPERTY_NOMENCLAT_TITLE
= "Nomencl. Title";
43 private static final String PROPERTY_URI
= "URI";
44 private static final String PROPERTY_JOURNAL
= "In Reference";
45 private static final String PROPERTY_PUBLICATION_YEAR
= "Publication Year";
47 private static ReferenceEditorInput instance
;
49 public static String
getID() {
54 protected List
<String
> getPropertyKeys_internal() {
55 List
<String
> propertyKeysInternal
= new ArrayList
<>();
56 propertyKeysInternal
.add(PROPERTY_NOMENCLATURAL_CACHE
);
57 propertyKeysInternal
.add(PROPERTY_PROTECT_NOMENCLATURAL_CACHE
);
58 propertyKeysInternal
.add(PROPERTY_TITLE
);
59 propertyKeysInternal
.add(PROPERTY_NOMENCLAT_TITLE
);
60 propertyKeysInternal
.add(PROPERTY_PUBLICATION_YEAR
);
61 propertyKeysInternal
.add(PROPERTY_JOURNAL
);
62 propertyKeysInternal
.add(PROPERTY_URI
);
63 return propertyKeysInternal
;
67 public Object
getPropertyValue(Reference cdmBase
, String property
) {
68 if(property
.equals(PROPERTY_NOMENCLATURAL_CACHE
)){
69 return cdmBase
.getAbbrevTitleCache();
71 else if(property
.equals(PROPERTY_PROTECT_NOMENCLATURAL_CACHE
)){
72 return cdmBase
.isProtectedAbbrevTitleCache();
74 else if(property
.equals(PROPERTY_TITLE
)){
75 return cdmBase
.getTitle();
77 else if(property
.equals(PROPERTY_NOMENCLAT_TITLE
)){
78 return cdmBase
.getAbbrevTitle();
80 else if(property
.equals(PROPERTY_PUBLICATION_YEAR
)){
81 if (cdmBase
.getDatePublished() != null){
83 if (cdmBase
.getDatePublished().getYear() != null){
84 result
= cdmBase
.getDatePublished().getYear();
86 if (cdmBase
.getDatePublishedString() != null && !result
.equals(cdmBase
.getDatePublishedString()) ) {
87 result
+= " (" + cdmBase
.getDatePublishedString()+")";
90 }else if(cdmBase
.getDatePublished() == null && cdmBase
.getInReference() != null ){
92 if (cdmBase
.getInReference().getDatePublished() != null && cdmBase
.getInReference().getDatePublished().getYear() != null){
93 result
= cdmBase
.getInReference().getDatePublished().getYear();
95 if (cdmBase
.getInReference().getDatePublishedString() != null && !result
.equals(cdmBase
.getInReference().getDatePublishedString()) ) {
96 result
+= " (" + cdmBase
.getInReference().getDatePublishedString()+")";
105 else if(property
.equals(PROPERTY_JOURNAL
)){
106 if (cdmBase
.getInReference() != null){
107 return cdmBase
.getInReference().getTitleCache();
113 else if(property
.equals(PROPERTY_URI
)){
114 if (cdmBase
.getUri() != null){
115 return cdmBase
.getUri().toString();
120 return super.getPropertyValue(cdmBase
, property
);
124 public boolean isBooleanProperty(String property
) {
125 if(property
.equals(PROPERTY_PROTECT_NOMENCLATURAL_CACHE
)){
128 return super.isBooleanProperty(property
);
132 public boolean isCacheProperty(String property
) {
133 if(property
.equals(PROPERTY_PROTECT_NOMENCLATURAL_CACHE
)){
136 return super.isBooleanProperty(property
);
140 public String
getName() {
141 return BulkEditorInputType
.REFERENCE
.label
;
144 public static AbstractBulkEditorInput
<Reference
> getInstance() {
145 if (instance
== null) {
146 instance
= new ReferenceEditorInput();
152 public boolean isMergingEnabled() {
157 public boolean isMarkerTypeEditingEnabled(MarkerType markerType
) {
158 if (MarkerType
.PUBLISH().equals(markerType
)) {
161 return super.isMarkerTypeEditingEnabled(markerType
);
165 protected long countEntities(IIdentifiableEntityServiceConfigurator configurator
) {
166 return CdmStore
.getService(IReferenceService
.class).countByTitle(configurator
);
170 public List
<Reference
> listEntities(IIdentifiableEntityServiceConfigurator configurator
) {
171 return CdmStore
.getSearchManager().findReferences(configurator
);
177 public Reference
loadEntity(UUID entityUuid
) {
178 List
<String
> propertyPaths
= Arrays
.asList(new String
[]{"*", "inReference.*", "authorTeam.*"});
179 return CdmStore
.getService(IReferenceService
.class).load(entityUuid
, propertyPaths
);
183 public boolean delete(Reference entity
, DeleteConfiguratorBase config
) throws ReferencedObjectUndeletableException
{
184 if (entity
.getUuid() != null){
185 return CdmStore
.getService(IReferenceService
.class).delete(entity
.getUuid()) != null;
192 public Reference
save(Reference entity
) {
193 return CdmStore
.getService(IReferenceService
.class).merge(entity
, true).getMergedEntity();
197 protected IEntityCreator
<Reference
> createEntityCreator() {
198 return new ReferenceCreator();
202 public List
<IBulkEditorSortProvider
<Reference
>> getSortProviders() {
203 List
<IBulkEditorSortProvider
<Reference
>> sortProviders
= super.getSortProviders();
205 sortProviders
.add(0, new IdentifiableEntitySortProvider
<Reference
>());
206 sortProviders
.add(1, new ReferenceSortProvider());
208 return sortProviders
;
212 public String
getTypeText(Object entity
) {
213 if(entity
instanceof Reference
){
214 return ((Reference
) entity
).getType().getMessage(CdmStore
.getDefaultLanguage());
216 return super.getTypeText(entity
);
220 public void merge() {