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){
82 String result
= cdmBase
.getDatePublished().getYear();
83 if (!cdmBase
.getDatePublished().getYear().equals(cdmBase
.getDatePublishedString()) && cdmBase
.getDatePublishedString() != null) {
84 result
+= " (" + cdmBase
.getDatePublishedString()+")";
87 }else if(cdmBase
.getDatePublished() == null && cdmBase
.getInReference() != null ){
88 String result
= cdmBase
.getInReference().getDatePublished().getYear();
89 if (!cdmBase
.getInReference().getDatePublished().getYear().equals(cdmBase
.getInReference().getDatePublishedString()) ) {
90 result
+= " (" + cdmBase
.getInReference().getDatePublishedString()+")";
99 else if(property
.equals(PROPERTY_JOURNAL
)){
100 if (cdmBase
.getInReference() != null){
101 return cdmBase
.getInReference().getTitleCache();
107 else if(property
.equals(PROPERTY_URI
)){
108 if (cdmBase
.getUri() != null){
109 return cdmBase
.getUri().toString();
114 return super.getPropertyValue(cdmBase
, property
);
118 public boolean isBooleanProperty(String property
) {
119 if(property
.equals(PROPERTY_PROTECT_NOMENCLATURAL_CACHE
)){
122 return super.isBooleanProperty(property
);
126 public boolean isCacheProperty(String property
) {
127 if(property
.equals(PROPERTY_PROTECT_NOMENCLATURAL_CACHE
)){
130 return super.isBooleanProperty(property
);
134 public String
getName() {
135 return BulkEditorInputType
.REFERENCE
.label
;
138 public static AbstractBulkEditorInput
<Reference
> getInstance() {
139 if (instance
== null) {
140 instance
= new ReferenceEditorInput();
146 public boolean isMergingEnabled() {
151 public boolean isMarkerTypeEditingEnabled(MarkerType markerType
) {
152 if (MarkerType
.PUBLISH().equals(markerType
)) {
155 return super.isMarkerTypeEditingEnabled(markerType
);
159 protected long countEntities(IIdentifiableEntityServiceConfigurator configurator
) {
160 return CdmStore
.getService(IReferenceService
.class).countByTitle(configurator
);
164 public List
<Reference
> listEntities(IIdentifiableEntityServiceConfigurator configurator
) {
165 return CdmStore
.getSearchManager().findReferences(configurator
);
171 public Reference
loadEntity(UUID entityUuid
) {
172 List
<String
> propertyPaths
= Arrays
.asList(new String
[]{"*", "inReference.*", "authorTeam.*"});
173 return CdmStore
.getService(IReferenceService
.class).load(entityUuid
, propertyPaths
);
177 public boolean delete(Reference entity
, DeleteConfiguratorBase config
) throws ReferencedObjectUndeletableException
{
178 if (entity
.getUuid() != null){
179 return CdmStore
.getService(IReferenceService
.class).delete(entity
.getUuid()) != null;
186 public Reference
save(Reference entity
) {
187 return CdmStore
.getService(IReferenceService
.class).merge(entity
, true).getMergedEntity();
191 protected IEntityCreator
<Reference
> createEntityCreator() {
192 return new ReferenceCreator();
196 public List
<IBulkEditorSortProvider
<Reference
>> getSortProviders() {
197 List
<IBulkEditorSortProvider
<Reference
>> sortProviders
= super.getSortProviders();
199 sortProviders
.add(0, new IdentifiableEntitySortProvider
<Reference
>());
200 sortProviders
.add(1, new ReferenceSortProvider());
202 return sortProviders
;
206 public String
getTypeText(Object entity
) {
207 if(entity
instanceof Reference
){
208 return ((Reference
) entity
).getType().getMessage(CdmStore
.getDefaultLanguage());
210 return super.getTypeText(entity
);
214 public void merge() {