Revision 36812
Added by Michele Artini about 9 years ago
modules/dnet-components/trunk/src/main/java/eu/dnetlib/enabling/datastructures/AbstractJsonResource.java | ||
---|---|---|
1 |
package eu.dnetlib.enabling.datastructures; |
|
2 |
|
|
3 |
import com.google.gson.Gson; |
|
4 |
|
|
5 |
import eu.dnetlib.enabling.annotations.DnetResource; |
|
6 |
import eu.dnetlib.rmi.objects.is.DnetDataStructure; |
|
7 |
import eu.dnetlib.rmi.soap.exceptions.InformationServiceException; |
|
8 |
|
|
9 |
public abstract class AbstractJsonResource implements BaseResource { |
|
10 |
|
|
11 |
private String code; |
|
12 |
private boolean valid = true; |
|
13 |
private String name; |
|
14 |
private String description; |
|
15 |
|
|
16 |
public String getCode() { |
|
17 |
return code; |
|
18 |
} |
|
19 |
|
|
20 |
public void setCode(final String code) { |
|
21 |
this.code = code; |
|
22 |
} |
|
23 |
|
|
24 |
public boolean isValid() { |
|
25 |
return valid; |
|
26 |
} |
|
27 |
|
|
28 |
public void setValid(final boolean valid) { |
|
29 |
this.valid = valid; |
|
30 |
} |
|
31 |
|
|
32 |
public String getName() { |
|
33 |
return name; |
|
34 |
} |
|
35 |
|
|
36 |
public void setName(final String name) { |
|
37 |
this.name = name; |
|
38 |
} |
|
39 |
|
|
40 |
public String getDescription() { |
|
41 |
return description; |
|
42 |
} |
|
43 |
|
|
44 |
public void setDescription(final String description) { |
|
45 |
this.description = description; |
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
public final DnetDataStructure asDnetDataStructure() throws InformationServiceException { |
|
50 |
if (getClass().isAnnotationPresent(DnetResource.class)) { |
|
51 |
final DnetDataStructure ds = new DnetDataStructure(); |
|
52 |
ds.setCode(code); |
|
53 |
ds.setType(getClass().getAnnotation(DnetResource.class).type()); |
|
54 |
ds.setValid(valid); |
|
55 |
ds.setName(name); |
|
56 |
ds.setDescription(description); |
|
57 |
ds.setContent(new Gson().toJson(this)); |
|
58 |
return ds; |
|
59 |
} else { |
|
60 |
throw new InformationServiceException("Missing DnetResource annotation in class " + getClass()); |
|
61 |
} |
|
62 |
} |
|
63 |
} |
modules/dnet-components/trunk/src/main/java/eu/dnetlib/enabling/datastructures/Vocabulary.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.util.TreeSet; |
4 | 4 |
|
5 |
import com.google.common.collect.Sets; |
|
6 |
|
|
5 | 7 |
import eu.dnetlib.enabling.annotations.DnetResource; |
6 | 8 |
import eu.dnetlib.rmi.objects.is.DnetResourceFormat; |
7 | 9 |
import eu.dnetlib.rmi.objects.is.DnetResourceKind; |
8 | 10 |
|
9 | 11 |
@DnetResource(type = "Vocabulary", kind = DnetResourceKind.CONFIGURATION, format = DnetResourceFormat.JSON) |
10 |
public class Vocabulary extends TreeSet<VocabularyTerms> {
|
|
12 |
public class Vocabulary extends AbstractJsonResource {
|
|
11 | 13 |
|
12 |
private static final long serialVersionUID = 1457952741071376416L;
|
|
14 |
private TreeSet<VocabularyTerms> terms = Sets.newTreeSet();
|
|
13 | 15 |
|
16 |
public TreeSet<VocabularyTerms> getTerms() { |
|
17 |
return terms; |
|
18 |
} |
|
19 |
|
|
20 |
public void setTerms(final TreeSet<VocabularyTerms> terms) { |
|
21 |
this.terms = terms; |
|
22 |
} |
|
23 |
|
|
14 | 24 |
} |
modules/dnet-components/trunk/src/main/java/eu/dnetlib/enabling/datastructures/CleaningRule.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.enabling.datastructures; |
2 | 2 |
|
3 |
import java.util.ArrayList;
|
|
3 |
import java.util.List; |
|
4 | 4 |
|
5 |
import com.google.common.collect.Lists; |
|
6 |
|
|
5 | 7 |
import eu.dnetlib.enabling.annotations.DnetResource; |
6 | 8 |
import eu.dnetlib.rmi.objects.is.DnetResourceFormat; |
7 | 9 |
import eu.dnetlib.rmi.objects.is.DnetResourceKind; |
8 | 10 |
|
9 | 11 |
@DnetResource(type = "CleaningRule", kind = DnetResourceKind.CONFIGURATION, format = DnetResourceFormat.JSON) |
10 |
public class CleaningRule extends ArrayList<AtomicCleaningRule> {
|
|
12 |
public class CleaningRule extends AbstractJsonResource {
|
|
11 | 13 |
|
12 |
private static final long serialVersionUID = -840852796902412057L;
|
|
14 |
private List<AtomicCleaningRule> rules = Lists.newArrayList();
|
|
13 | 15 |
|
16 |
public List<AtomicCleaningRule> getRules() { |
|
17 |
return rules; |
|
18 |
} |
|
19 |
|
|
20 |
public void setRules(final List<AtomicCleaningRule> rules) { |
|
21 |
this.rules = rules; |
|
22 |
} |
|
23 |
|
|
14 | 24 |
} |
modules/dnet-components/trunk/src/main/java/eu/dnetlib/enabling/datastructures/Workflow.java | ||
---|---|---|
1 |
package eu.dnetlib.enabling.datastructures; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
|
|
5 |
import javax.xml.bind.annotation.XmlRootElement; |
|
6 |
|
|
7 |
import org.dom4j.Document; |
|
8 |
import org.dom4j.DocumentException; |
|
9 |
import org.springframework.core.io.Resource; |
|
10 |
|
|
11 |
import eu.dnetlib.enabling.annotations.DnetResource; |
|
12 |
import eu.dnetlib.rmi.objects.is.DnetResourceFormat; |
|
13 |
import eu.dnetlib.rmi.objects.is.DnetResourceKind; |
|
14 |
|
|
15 |
@XmlRootElement |
|
16 |
@DnetResource(type = "Workflow", kind = DnetResourceKind.CONFIGURATION, format = DnetResourceFormat.XML) |
|
17 |
public class Workflow extends AbstractXmlResource { |
|
18 |
|
|
19 |
public Workflow(final Resource res) throws IOException, DocumentException { |
|
20 |
super(res); |
|
21 |
} |
|
22 |
|
|
23 |
@Override |
|
24 |
protected String getName(final Document doc) { |
|
25 |
return doc.valueOf("/process-definition/@name"); |
|
26 |
} |
|
27 |
|
|
28 |
@Override |
|
29 |
protected String getCode(final Document doc) { |
|
30 |
return doc.valueOf("/process-definition/@name"); |
|
31 |
} |
|
32 |
|
|
33 |
} |
modules/dnet-components/trunk/src/main/java/eu/dnetlib/enabling/datastructures/MDStore.java | ||
---|---|---|
10 | 10 |
|
11 | 11 |
@XmlRootElement |
12 | 12 |
@DnetResource(type = "MDStore", kind = DnetResourceKind.UNIT, format = DnetResourceFormat.JSON) |
13 |
public class MDStore { |
|
13 |
public class MDStore extends AbstractJsonResource {
|
|
14 | 14 |
|
15 | 15 |
private int size; |
16 | 16 |
private Date lastUpdate; |
modules/dnet-components/trunk/src/main/java/eu/dnetlib/enabling/datastructures/GroovyRule.java | ||
---|---|---|
5 | 5 |
import eu.dnetlib.rmi.objects.is.DnetResourceKind; |
6 | 6 |
|
7 | 7 |
@DnetResource(type = "GroovyRule", kind = DnetResourceKind.CONFIGURATION, format = DnetResourceFormat.JSON) |
8 |
public class GroovyRule { |
|
8 |
public class GroovyRule extends AbstractJsonResource {
|
|
9 | 9 |
|
10 | 10 |
private String classpath; |
11 | 11 |
private String mainClass; |
modules/dnet-components/trunk/src/main/java/eu/dnetlib/enabling/datastructures/AbstractTextResource.java | ||
---|---|---|
1 |
package eu.dnetlib.enabling.datastructures; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
|
|
5 |
import org.apache.commons.io.IOUtils; |
|
6 |
import org.springframework.core.io.Resource; |
|
7 |
|
|
8 |
import eu.dnetlib.enabling.annotations.DnetResource; |
|
9 |
import eu.dnetlib.rmi.objects.is.DnetDataStructure; |
|
10 |
import eu.dnetlib.rmi.soap.exceptions.InformationServiceException; |
|
11 |
|
|
12 |
public class AbstractTextResource implements BaseResource { |
|
13 |
|
|
14 |
private Resource resource; |
|
15 |
|
|
16 |
public AbstractTextResource(final Resource resource) { |
|
17 |
this.resource = resource; |
|
18 |
} |
|
19 |
|
|
20 |
@Override |
|
21 |
public DnetDataStructure asDnetDataStructure() throws InformationServiceException { |
|
22 |
try { |
|
23 |
if (getClass().isAnnotationPresent(DnetResource.class)) { |
|
24 |
final String code = resource.getFilename(); |
|
25 |
final DnetDataStructure ds = new DnetDataStructure(); |
|
26 |
ds.setCode(code); |
|
27 |
ds.setType(getClass().getAnnotation(DnetResource.class).type()); |
|
28 |
ds.setValid(true); |
|
29 |
ds.setName(code); |
|
30 |
ds.setDescription(""); |
|
31 |
ds.setContent(IOUtils.toString(resource.getInputStream())); |
|
32 |
return ds; |
|
33 |
} else { |
|
34 |
throw new InformationServiceException("Missing DnetResource annotation in class " + getClass()); |
|
35 |
} |
|
36 |
} catch (IOException e) { |
|
37 |
throw new InformationServiceException("Error reading resource " + resource.getFilename()); |
|
38 |
} |
|
39 |
} |
|
40 |
|
|
41 |
} |
modules/dnet-components/trunk/src/main/java/eu/dnetlib/enabling/datastructures/MetaWorkflow.java | ||
---|---|---|
10 | 10 |
|
11 | 11 |
@XmlRootElement |
12 | 12 |
@DnetResource(type = "MetaWorkflow", kind = DnetResourceKind.UNIT, format = DnetResourceFormat.JSON) |
13 |
public class MetaWorkflow { |
|
13 |
public class MetaWorkflow extends AbstractJsonResource {
|
|
14 | 14 |
|
15 | 15 |
@XmlEnum |
16 | 16 |
public enum Status { |
... | ... | |
45 | 45 |
this.section = section; |
46 | 46 |
} |
47 | 47 |
|
48 |
@Override |
|
48 | 49 |
public String getName() { |
49 | 50 |
return name; |
50 | 51 |
} |
51 | 52 |
|
53 |
@Override |
|
52 | 54 |
public void setName(final String name) { |
53 | 55 |
this.name = name; |
54 | 56 |
} |
modules/dnet-components/trunk/src/main/java/eu/dnetlib/enabling/datastructures/BaseResource.java | ||
---|---|---|
1 |
package eu.dnetlib.enabling.datastructures; |
|
2 |
|
|
3 |
import eu.dnetlib.rmi.objects.is.DnetDataStructure; |
|
4 |
import eu.dnetlib.rmi.soap.exceptions.InformationServiceException; |
|
5 |
|
|
6 |
public interface BaseResource { |
|
7 |
|
|
8 |
DnetDataStructure asDnetDataStructure() throws InformationServiceException; |
|
9 |
} |
modules/dnet-components/trunk/src/main/java/eu/dnetlib/enabling/datastructures/ObjectStore.java | ||
---|---|---|
10 | 10 |
|
11 | 11 |
@XmlRootElement |
12 | 12 |
@DnetResource(type = "ObjectStore", kind = DnetResourceKind.UNIT, format = DnetResourceFormat.JSON) |
13 |
public class ObjectStore { |
|
13 |
public class ObjectStore extends AbstractJsonResource {
|
|
14 | 14 |
|
15 | 15 |
private int size; |
16 | 16 |
private Date lastUpdate; |
modules/dnet-components/trunk/src/main/java/eu/dnetlib/enabling/datastructures/MetadataFormat.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.enabling.datastructures; |
2 | 2 |
|
3 |
import java.io.IOException; |
|
4 |
|
|
3 | 5 |
import javax.xml.bind.annotation.XmlRootElement; |
4 | 6 |
|
7 |
import org.dom4j.Document; |
|
8 |
import org.dom4j.DocumentException; |
|
9 |
import org.springframework.core.io.Resource; |
|
10 |
|
|
5 | 11 |
import eu.dnetlib.enabling.annotations.DnetResource; |
6 | 12 |
import eu.dnetlib.rmi.objects.is.DnetResourceFormat; |
7 | 13 |
import eu.dnetlib.rmi.objects.is.DnetResourceKind; |
8 | 14 |
|
9 | 15 |
@XmlRootElement |
10 | 16 |
@DnetResource(type = "MetadataFormat", kind = DnetResourceKind.CONFIGURATION, format = DnetResourceFormat.XML) |
11 |
public class MetadataFormat { |
|
17 |
public class MetadataFormat extends AbstractXmlResource {
|
|
12 | 18 |
|
19 |
public MetadataFormat(final Resource res) throws IOException, DocumentException { |
|
20 |
super(res); |
|
21 |
} |
|
22 |
|
|
23 |
@Override |
|
24 |
protected String getName(final Document doc) { |
|
25 |
return doc.valueOf("/format/@name"); |
|
26 |
} |
|
27 |
|
|
28 |
@Override |
|
29 |
protected String getCode(final Document doc) { |
|
30 |
return doc.valueOf("/format/@name"); |
|
31 |
} |
|
32 |
|
|
13 | 33 |
} |
modules/dnet-components/trunk/src/main/java/eu/dnetlib/enabling/datastructures/Datasource.java | ||
---|---|---|
16 | 16 |
|
17 | 17 |
@XmlRootElement |
18 | 18 |
@DnetResource(format = DnetResourceFormat.JSON, kind = DnetResourceKind.UNIT, type = DatasourceConstants.DATASOURCE_TYPE) |
19 |
public class Datasource { |
|
19 |
public class Datasource extends AbstractJsonResource {
|
|
20 | 20 |
|
21 | 21 |
private String id; |
22 | 22 |
private String officialName; |
... | ... | |
315 | 315 |
this.mergehomonyms = mergehomonyms; |
316 | 316 |
} |
317 | 317 |
|
318 |
@Override |
|
318 | 319 |
public String getDescription() { |
319 | 320 |
return description; |
320 | 321 |
} |
321 | 322 |
|
323 |
@Override |
|
322 | 324 |
public void setDescription(final String description) { |
323 | 325 |
this.description = description; |
324 | 326 |
} |
modules/dnet-components/trunk/src/main/java/eu/dnetlib/enabling/datastructures/AbstractXmlResource.java | ||
---|---|---|
1 |
package eu.dnetlib.enabling.datastructures; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
import java.io.StringReader; |
|
5 |
|
|
6 |
import org.dom4j.Document; |
|
7 |
import org.dom4j.DocumentException; |
|
8 |
import org.dom4j.io.SAXReader; |
|
9 |
import org.springframework.core.io.Resource; |
|
10 |
|
|
11 |
import eu.dnetlib.enabling.annotations.DnetResource; |
|
12 |
import eu.dnetlib.rmi.objects.is.DnetDataStructure; |
|
13 |
import eu.dnetlib.rmi.soap.exceptions.InformationServiceException; |
|
14 |
|
|
15 |
public abstract class AbstractXmlResource implements BaseResource { |
|
16 |
|
|
17 |
private transient Document doc; |
|
18 |
|
|
19 |
public AbstractXmlResource(final String xml) throws DocumentException { |
|
20 |
this.doc = new SAXReader().read(new StringReader(xml)); |
|
21 |
} |
|
22 |
|
|
23 |
public AbstractXmlResource(final Resource res) throws IOException, DocumentException { |
|
24 |
this.doc = new SAXReader().read(res.getInputStream()); |
|
25 |
} |
|
26 |
|
|
27 |
public final Document asDocument() { |
|
28 |
return doc; |
|
29 |
} |
|
30 |
|
|
31 |
abstract protected String getName(Document doc); |
|
32 |
|
|
33 |
abstract protected String getCode(Document doc); |
|
34 |
|
|
35 |
protected String getDescription(final Document doc) { |
|
36 |
return ""; |
|
37 |
} |
|
38 |
|
|
39 |
protected boolean isValid(final Document doc) { |
|
40 |
return true; |
|
41 |
} |
|
42 |
|
|
43 |
@Override |
|
44 |
public DnetDataStructure asDnetDataStructure() throws InformationServiceException { |
|
45 |
if (getClass().isAnnotationPresent(DnetResource.class)) { |
|
46 |
final DnetDataStructure ds = new DnetDataStructure(); |
|
47 |
ds.setCode(getCode(doc)); |
|
48 |
ds.setType(getClass().getAnnotation(DnetResource.class).type()); |
|
49 |
ds.setValid(isValid(doc)); |
|
50 |
ds.setName(getName(doc)); |
|
51 |
ds.setDescription(getDescription(doc)); |
|
52 |
ds.setContent(doc.asXML()); |
|
53 |
return ds; |
|
54 |
} else { |
|
55 |
throw new InformationServiceException("Missing DnetResource annotation in class " + getClass()); |
|
56 |
} |
|
57 |
} |
|
58 |
} |
modules/dnet-components/trunk/src/main/java/eu/dnetlib/enabling/datastructures/TransformationRule.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.enabling.datastructures; |
2 | 2 |
|
3 |
import org.springframework.core.io.Resource; |
|
4 |
|
|
3 | 5 |
import eu.dnetlib.enabling.annotations.DnetResource; |
4 | 6 |
import eu.dnetlib.rmi.objects.is.DnetResourceFormat; |
5 | 7 |
import eu.dnetlib.rmi.objects.is.DnetResourceKind; |
6 | 8 |
|
7 | 9 |
@DnetResource(type = "TransformationRule", kind = DnetResourceKind.CONFIGURATION, format = DnetResourceFormat.TEXT) |
8 |
public class TransformationRule { |
|
10 |
public class TransformationRule extends AbstractTextResource {
|
|
9 | 11 |
|
10 |
private String code; |
|
11 |
|
|
12 |
public TransformationRule() {} |
|
13 |
|
|
14 |
public TransformationRule(final String code) { |
|
15 |
this.code = code; |
|
12 |
public TransformationRule(final Resource resource) { |
|
13 |
super(resource); |
|
16 | 14 |
} |
17 | 15 |
|
18 |
public String getCode() { |
|
19 |
return code; |
|
20 |
} |
|
21 |
|
|
22 |
public void setCode(final String code) { |
|
23 |
this.code = code; |
|
24 |
} |
|
25 |
|
|
26 |
@Override |
|
27 |
public String toString() { |
|
28 |
return getCode(); |
|
29 |
} |
|
30 |
|
|
31 | 16 |
} |
modules/dnet-node-services/trunk/src/main/java/eu/dnetlib/enabling/nodeManager/ContentInitializer.java | ||
---|---|---|
42 | 42 |
try { |
43 | 43 |
log.info("Content initialization - START"); |
44 | 44 |
registerAnnotatedResouceTypes(basePackage); |
45 |
// registerServices(); // TO DELETE |
|
46 | 45 |
registerDatastructures(initDsPath, false); |
47 | 46 |
log.info("Content initialization - END"); |
48 | 47 |
} catch (Throwable e) { |
modules/dnet-node-services/trunk/src/main/java/eu/dnetlib/data/resultSet/cleaner/VocabularyRule.java | ||
---|---|---|
31 | 31 |
this.vocabularies = vocabularies; |
32 | 32 |
for (final String vocName : vocabularies) { |
33 | 33 |
try { |
34 |
for (VocabularyTerms term : isClient.getResourceByCode(vocName, Vocabulary.class)) { |
|
34 |
for (VocabularyTerms term : isClient.getResourceByCode(vocName, Vocabulary.class).getTerms()) {
|
|
35 | 35 |
final String code = term.getCode(); |
36 | 36 |
validTerms.add(code.toLowerCase()); |
37 | 37 |
synonyms.put(code.toLowerCase(), code); |
modules/dnet-node-services/trunk/src/main/java/eu/dnetlib/data/resultSet/cleaner/CleanerFactory.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
public Cleaner createCleaner(final CleaningRule rule) { |
21 | 21 |
|
22 |
final List<XPathCleaningRule> xpathRules = Lists.transform(rule, new Function<AtomicCleaningRule, XPathCleaningRule>() { |
|
22 |
final List<XPathCleaningRule> xpathRules = Lists.transform(rule.getRules(), new Function<AtomicCleaningRule, XPathCleaningRule>() {
|
|
23 | 23 |
|
24 | 24 |
@Override |
25 | 25 |
public XPathCleaningRule apply(final AtomicCleaningRule r) { |
Also available in: Unified diff
BaseResource interface