-
Notifications
You must be signed in to change notification settings - Fork 1
/
DefaultAIPTagging.java
103 lines (92 loc) · 3.58 KB
/
DefaultAIPTagging.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
* Copyright 2017-2022 CNES - CENTRE NATIONAL d'ETUDES SPATIALES
*
* This file is part of REGARDS.
*
* REGARDS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* REGARDS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with REGARDS. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.cnes.regards.modules.ingest.service.chain.plugin;
import fr.cnes.regards.framework.modules.plugins.annotations.Plugin;
import fr.cnes.regards.framework.modules.plugins.annotations.PluginInit;
import fr.cnes.regards.framework.modules.plugins.annotations.PluginParameter;
import fr.cnes.regards.framework.utils.plugins.PluginUtilsRuntimeException;
import fr.cnes.regards.modules.ingest.domain.exception.TagAIPException;
import fr.cnes.regards.modules.ingest.domain.plugin.IAipTagging;
import fr.cnes.regards.modules.ingest.dto.aip.AIP;
import java.util.List;
import java.util.Map;
/**
* Default AIP tagging plugin that can manage either tags or links or both.<br/>
* Tags are basic {@link String}.<br/>
* Links are key value pairs of {@link String}<br/>
* <br/>
* Sample tags:
* <ul>
* <li>FRANCE</li>
* <li>SPATIAL</li>
* </ul>
* <p>
* Sample links:
* <ul>
* <li>CNES -> http://www.cnes.fr</li>
* <li>FITS -> https://www.iana.org/assignments/media-types/application/fits</li>
* </ul>
*
* @author Marc Sordi
*/
@Plugin(author = "REGARDS Team",
description = "Default plugin for AIP tagging",
id = "DefaultAIPTagging",
version = "1.0.0",
contact = "regards@c-s.fr",
license = "GPLv3",
owner = "CNES",
url = "https://regardsoss.github.io/")
public class DefaultAIPTagging implements IAipTagging {
public static final String FIELD_NAME_TAGS = "tags"; // Useful for testing
public static final String FIELD_NAME_LINKS = "links"; // Useful for testing
@PluginParameter(label = "Tags",
description = "List of tags useful to classify AIP for business purpose and harvesting",
optional = true)
private List<String> tags;
@PluginParameter(keylabel = "Link tag", label = "Link", description = "List of links", optional = true)
private Map<String, String> links;
@PluginInit
public void init() {
// At least, one tag or link is required
if ((tags == null || tags.isEmpty()) && (links == null || links.isEmpty())) {
throw new PluginUtilsRuntimeException(String.format("Tags or links is required in default tag plugin : %s",
this.getClass().getName()));
}
}
@Override
public void tag(List<AIP> aips) throws TagAIPException {
if (aips != null) {
for (AIP aip : aips) {
addTags(aip, tags);
addLinks(aip, links);
}
}
}
private void addTags(AIP aip, List<String> tags) {
if (tags != null && !tags.isEmpty()) {
aip.withContextTags(tags.toArray(new String[tags.size()]));
}
}
private void addLinks(AIP aip, Map<String, String> links) {
if (links != null) {
links.forEach((k, v) -> aip.withContextInformation(k, v));
}
}
}