1
|
/**
|
2
|
* Copyright (C) 2016 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.bulkeditor.input;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.Arrays;
|
13
|
import java.util.List;
|
14
|
import java.util.UUID;
|
15
|
|
16
|
import eu.etaxonomy.cdm.api.service.IMediaService;
|
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.config.MediaDeletionConfigurator;
|
20
|
import eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException;
|
21
|
import eu.etaxonomy.cdm.model.common.Language;
|
22
|
import eu.etaxonomy.cdm.model.media.Media;
|
23
|
import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
|
24
|
import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorSortProvider;
|
25
|
import eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator.MediaCreator;
|
26
|
import eu.etaxonomy.taxeditor.bulkeditor.input.sortprovider.IdentifiableEntitySortProvider;
|
27
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
28
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
29
|
|
30
|
/**
|
31
|
* @author k.luther
|
32
|
* @date 10.03.2016
|
33
|
*
|
34
|
*/
|
35
|
public class MediaEditorInput extends AbstractBulkEditorInput<Media> {
|
36
|
public static final String ID = "bulkeditor.input.media";
|
37
|
|
38
|
private static MediaEditorInput instance;
|
39
|
|
40
|
private static final String PROPERTY_TITLE = "Title";
|
41
|
private static final String PROPERTY_DESCRIPTION = "Description";
|
42
|
|
43
|
private Language globalLanguage = PreferencesUtil.getGlobalLanguage();
|
44
|
|
45
|
public static String getID() {
|
46
|
return ID;
|
47
|
}
|
48
|
|
49
|
public static AbstractBulkEditorInput getInstance() {
|
50
|
if (instance == null) {
|
51
|
instance = new MediaEditorInput();
|
52
|
}
|
53
|
return instance;
|
54
|
}
|
55
|
|
56
|
@Override
|
57
|
protected List<String> getPropertyKeys_internal() {
|
58
|
List<String> propertyKeysInternal = new ArrayList<>();
|
59
|
propertyKeysInternal.add(PROPERTY_TITLE);
|
60
|
propertyKeysInternal.add(PROPERTY_DESCRIPTION);
|
61
|
return propertyKeysInternal;
|
62
|
}
|
63
|
|
64
|
@Override
|
65
|
public Object getPropertyValue(Media cdmBase, String property) {
|
66
|
if(property.equals(PROPERTY_TITLE)){
|
67
|
return cdmBase.getTitle();
|
68
|
}
|
69
|
else if(property.equals(PROPERTY_DESCRIPTION)){
|
70
|
return cdmBase.getDescription(globalLanguage);
|
71
|
}
|
72
|
return super.getPropertyValue(cdmBase, property);
|
73
|
}
|
74
|
|
75
|
@Override
|
76
|
public String getName() {
|
77
|
return BulkEditorInputType.MEDIA.label;
|
78
|
}
|
79
|
|
80
|
@Override
|
81
|
public Media save(Media entity) {
|
82
|
return CdmStore.getService(IMediaService.class).merge(entity, true).getMergedEntity();
|
83
|
|
84
|
}
|
85
|
|
86
|
@Override
|
87
|
public boolean delete(Media entity, DeleteConfiguratorBase config) throws ReferencedObjectUndeletableException {
|
88
|
MediaDeletionConfigurator mediaConfig = null;
|
89
|
if (config instanceof MediaDeletionConfigurator){
|
90
|
mediaConfig = (MediaDeletionConfigurator) config;
|
91
|
} else{
|
92
|
|
93
|
}
|
94
|
return CdmStore.getService(IMediaService.class).delete(entity.getUuid(), mediaConfig) != null;
|
95
|
}
|
96
|
|
97
|
@Override
|
98
|
protected long countEntities(IIdentifiableEntityServiceConfigurator configurator) {
|
99
|
return CdmStore.getService(IMediaService.class).countByTitle(configurator);
|
100
|
}
|
101
|
|
102
|
@Override
|
103
|
protected List<Media> listEntities(IIdentifiableEntityServiceConfigurator configurator) {
|
104
|
return CdmStore.getSearchManager().findMedia(configurator);
|
105
|
}
|
106
|
|
107
|
@Override
|
108
|
protected IEntityCreator<Media> createEntityCreator() {
|
109
|
return new MediaCreator();
|
110
|
}
|
111
|
|
112
|
@Override
|
113
|
public void merge() {
|
114
|
// TODO Auto-generated method stub
|
115
|
|
116
|
}
|
117
|
|
118
|
@Override
|
119
|
public List<IBulkEditorSortProvider<Media>> getSortProviders() {
|
120
|
List<IBulkEditorSortProvider<Media>> sortProviders = super.getSortProviders();
|
121
|
|
122
|
sortProviders.add(0, new IdentifiableEntitySortProvider<Media>());
|
123
|
|
124
|
return sortProviders;
|
125
|
}
|
126
|
|
127
|
@Override
|
128
|
protected Media loadEntity(UUID entityUuid) {
|
129
|
List<String> propertyPaths = Arrays.asList(new String[]{});
|
130
|
return CdmStore.getService(IMediaService.class).load(entityUuid, propertyPaths);
|
131
|
}
|
132
|
|
133
|
}
|