Project

General

Profile

« Previous | Next » 

Revision 37126

resource properties management

View differences:

modules/dnet-information-service/trunk/src/main/java/eu/dnetlib/enabling/is/hib/utils/HibObjectHelper.java
38 38
			hib.getProtocols().add(new HibServiceProtocol(new HibServiceProtocolId(hib, e.getKey()), e.getValue()));
39 39
		}
40 40
		for (Entry<String, String> e : service.getProperties().entrySet()) {
41
			hib.getProperties().add(new HibDnetResourceProperty(hib, e.getKey(), e.getValue()));
41
			if (e.getValue() != null) {
42
				hib.getProperties().add(new HibDnetResourceProperty(hib, e.getKey(), e.getValue()));
43
			}
42 44
		}
43 45
		for (BlackboardMessageContainer b : service.getBlackboard()) {
44 46
			hib.getBlackboard().add(new HibBlackboardMessage(hib, b));
......
63 65
		hib.setValid(ds.isValid());
64 66

  
65 67
		for (Entry<String, String> e : ds.getProperties().entrySet()) {
66

  
67
			System.out.println(" **************** K = " + e.getKey());
68

  
69
			hib.getProperties().add(new HibDnetResourceProperty(hib, e.getKey(), e.getValue()));
68
			if (e.getValue() != null) {
69
				System.out.println(" **************** K = " + e.getKey());
70
				hib.getProperties().add(new HibDnetResourceProperty(hib, e.getKey(), e.getValue()));
71
			}
70 72
		}
71 73

  
72 74
		if (StringUtils.isNotBlank(ds.getServiceId())) {
modules/dnet-information-service/trunk/src/main/java/eu/dnetlib/enabling/is/hib/objects/HibDnetResource.java
37 37
	@Column(name = "date", nullable = false, insertable = false, updatable = false)
38 38
	private Date date;
39 39

  
40
	@OneToMany(mappedBy = "resource", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
40
	@OneToMany(mappedBy = "id.resource", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
41 41
	private Set<HibDnetResourceProperty> properties = Sets.newLinkedHashSet();
42 42

  
43 43
	public HibDnetResource() {}
modules/dnet-information-service/trunk/src/main/java/eu/dnetlib/enabling/is/hib/objects/HibDnetResourcePropertyId.java
1
package eu.dnetlib.enabling.is.hib.objects;
2

  
3
import java.io.Serializable;
4

  
5
import javax.persistence.Column;
6
import javax.persistence.Embeddable;
7
import javax.persistence.JoinColumn;
8
import javax.persistence.ManyToOne;
9
import javax.persistence.Transient;
10

  
11
import org.apache.commons.lang.builder.HashCodeBuilder;
12

  
13
@Embeddable
14
public class HibDnetResourcePropertyId implements Serializable {
15

  
16
	@Transient
17
	private static final long serialVersionUID = 612491084747663805L;
18

  
19
	@ManyToOne
20
	@JoinColumn(name = "resource", nullable = false)
21
	private HibDnetResource resource;
22

  
23
	@Column(name = "name", nullable = false)
24
	private String name;
25

  
26
	@Column(name = "value")
27
	private String value;
28

  
29
	public HibDnetResourcePropertyId() {}
30

  
31
	public HibDnetResourcePropertyId(final HibDnetResource resource, final String name, final String value) {
32
		this.resource = resource;
33
		this.name = name;
34
		this.value = value;
35
	}
36

  
37
	public HibDnetResource getResource() {
38
		return resource;
39
	}
40

  
41
	public void setResource(final HibDnetResource resource) {
42
		this.resource = resource;
43
	}
44

  
45
	public String getName() {
46
		return name;
47
	}
48

  
49
	public void setName(final String name) {
50
		this.name = name;
51
	}
52

  
53
	public String getValue() {
54
		return value;
55
	}
56

  
57
	public void setValue(final String value) {
58
		this.value = value;
59
	}
60

  
61
	@Override
62
	public int hashCode() {
63
		return new HashCodeBuilder().append(resource.getId()).append(name).append(value).toHashCode();
64
	}
65
}
modules/dnet-information-service/trunk/src/main/java/eu/dnetlib/enabling/is/hib/objects/HibDnetResourceProperty.java
2 2

  
3 3
import java.io.Serializable;
4 4

  
5
import javax.persistence.Column;
5
import javax.persistence.EmbeddedId;
6 6
import javax.persistence.Entity;
7
import javax.persistence.Id;
8
import javax.persistence.JoinColumn;
9
import javax.persistence.ManyToOne;
10 7
import javax.persistence.Table;
11 8
import javax.persistence.Transient;
12 9

  
......
15 12
public class HibDnetResourceProperty extends HibDnetObject implements Serializable {
16 13

  
17 14
	@Transient
18
	private static final long serialVersionUID = 612491084747663805L;
15
	private static final long serialVersionUID = -2095052466902711468L;
19 16

  
20
	@Id
21
	@Column(name = "id", insertable = false)
22
	private int id;
17
	@EmbeddedId
18
	private HibDnetResourcePropertyId id;
23 19

  
24
	@ManyToOne
25
	@JoinColumn(name = "resource", nullable = false)
26
	private HibDnetResource resource;
27

  
28
	@Column(name = "name", nullable = false)
29
	private String name;
30

  
31
	@Column(name = "value")
32
	private String value;
33

  
34 20
	public HibDnetResourceProperty() {}
35 21

  
36
	public HibDnetResourceProperty(final int id, final HibDnetResource resource, final String name, final String value) {
22
	public HibDnetResourceProperty(final HibDnetResourcePropertyId id) {
37 23
		this.id = id;
38
		this.resource = resource;
39
		this.name = name;
40
		this.value = value;
41 24
	}
42 25

  
43 26
	public HibDnetResourceProperty(final HibDnetResource resource, final String name, final String value) {
44
		this(-1, resource, name, value);
27
		this.id = new HibDnetResourcePropertyId(resource, name, value);
45 28
	}
46 29

  
47
	public int getId() {
30
	public final HibDnetResourcePropertyId getId() {
48 31
		return id;
49 32
	}
50 33

  
51
	public void setId(final int id) {
34
	public final void setId(final HibDnetResourcePropertyId id) {
52 35
		this.id = id;
53 36
	}
54 37

  
55
	public HibDnetResource getResource() {
56
		return resource;
57
	}
58

  
59
	public void setResource(final HibDnetResource resource) {
60
		this.resource = resource;
61
	}
62

  
63 38
	public String getName() {
64
		return name;
39
		return id.getName();
65 40
	}
66 41

  
67
	public void setName(final String name) {
68
		this.name = name;
69
	}
70

  
71 42
	public String getValue() {
72
		return value;
43
		return id.getValue();
73 44
	}
74 45

  
75
	public void setValue(final String value) {
76
		this.value = value;
77
	}
78

  
79 46
	@Override
80 47
	public int hashCode() {
81
		return id;
48
		return id.hashCode();
82 49
	}
83 50
}
modules/dnet-information-service/trunk/src/main/resources/eu/dnetlib/enabling/is/setup/is_base.sql
28 28
);
29 29

  
30 30
CREATE TABLE IF NOT EXISTS resource_properties (
31
	id       serial       NOT NULL PRIMARY KEY,
32 31
	resource varchar(255) NOT NULL REFERENCES resources(id) ON DELETE CASCADE,
33 32
	name     varchar(255) NOT NULL,
34
	value    varchar(255)
33
	value    varchar(255) NOT NULL,
34
	PRIMARY KEY (resource, name, value)
35 35
);
36 36

  
37 37
CREATE TABLE IF NOT EXISTS service_protocols (
modules/dnet-components/trunk/src/main/java/eu/dnetlib/enabling/datastructures/AbstractJsonResource.java
3 3
import com.google.gson.Gson;
4 4

  
5 5
import eu.dnetlib.enabling.annotations.DnetResource;
6
import eu.dnetlib.enabling.utils.DnetAnnotationUtils;
6 7
import eu.dnetlib.rmi.objects.is.DnetDataStructure;
7 8
import eu.dnetlib.rmi.soap.exceptions.InformationServiceException;
8 9

  
......
55 56
			ds.setName(name);
56 57
			ds.setDescription(description);
57 58
			ds.setContent(new Gson().toJson(this));
59
			ds.setProperties(DnetAnnotationUtils.getIndexedFields(this));
58 60
			return ds;
59 61
		} else {
60 62
			throw new InformationServiceException("Missing DnetResource annotation in class " + getClass());

Also available in: Unified diff