1 package org.lsst.ccs.config;
2
3
4 import org.hibernate.annotations.Immutable;
5 import org.lsst.gruth.jutils.ComponentNode;
6
7 import javax.persistence.*;
8 import java.util.Collections;
9 import java.util.HashSet;
10 import java.util.Properties;
11 import java.util.Set;
12
13
14
15
16
17
18
19 @Entity
20 @Immutable
21
22 class PastConfigProfile extends ConfigProfile {
23 private static final long serialVersionUID = 1522860009687523071L;
24
25 @Id
26 private long id ;
27
28 @ManyToOne (fetch=FetchType.EAGER)
29 private GhostSubsystemDescription subsystemDesc ;
30
31
32
33
34 @OneToMany (cascade = CascadeType.ALL, fetch=FetchType.EAGER)
35 private
36
37
38
39 PastConfigProfile() {
40 }
41
42
43
44
45
46
47
48
49 public PastConfigProfile(GhostSubsystemDescription ghost, AConfigProfile oldProfile) {
50 super(oldProfile.getName(), oldProfile.getTag(), oldProfile.getUserName(), oldProfile.getLevel()) ;
51 if(oldProfile.getId() == 0L) {
52 throw new IllegalArgumentException("trying to create history date from non registered data") ;
53 }
54
55 if(ghost.getId() != oldProfile.getSubsystemId()) {
56 throw new IllegalArgumentException("ghost and profile have no common ID");
57 }
58 this.subsystemDesc = ghost ;
59 this.id = oldProfile.getId() ;
60 this.setStartTimestamp(oldProfile.getStartTimestamp());
61 Set<PastParameterConfiguration> set = new HashSet<PastParameterConfiguration>();
62
63 for(AParameterConfiguration conf : oldProfile.getParameterConfigurations()){
64 ParameterDescription description = ghost.fetch(conf) ;
65 GhostParameterDescription ghostDesc = (GhostParameterDescription) description ;
66 PastParameterConfiguration pastConf = new PastParameterConfiguration(ghostDesc, conf);
67 set.add(pastConf) ;
68 }
69 parameterConfigurations = Collections.unmodifiableSet(set) ;
70 this.setPreviousConfigID(oldProfile.getPreviousConfigID());
71 long endDate = System.currentTimeMillis() ;
72 this.setEndTimestamp(endDate);
73 oldProfile.setEndTimestamp(endDate);
74 }
75
76
77
78 @Override
79 protected long getId() {
80 return id;
81 }
82
83 @Override
84 protected void setId(long id) {
85 this.id = id ;
86 }
87
88
89 @Override
90 public SubsystemDescription getSubsystemDescription() {
91 return this.subsystemDesc ;
92 }
93
94 @Override
95 public Set<? extends ParameterConfiguration> getModifiedParameters() {
96 return this.parameterConfigurations ;
97 }
98
99 @Override
100 public void temporaryChangeConfigurationValue(ParameterConfiguration parameter, long time, String value) {
101 throw new ImmutableStateException("no modification of deprecated data") ;
102 }
103 public ParameterConfiguration temporaryChangeConfigurationValue(String parameterPath, long time, String value) {
104 throw new ImmutableStateException("no modification of deprecated data") ;
105 }
106
107 @Override
108 public void mergeProperties(Properties props) {
109 throw new ImmutableStateException("no modification of deprecated data") ;
110 }
111
112 @Override
113 public void addParameterConfigurations(ParameterConfiguration... parameterConfigurations) {
114 throw new ImmutableStateException("no modification of deprecated data") ;
115 }
116
117 @Override
118 public void removeParameterConfigurations(ParameterConfiguration... parameterConfigurations) {
119 throw new ImmutableStateException("no modification of deprecated data") ;
120 }
121
122 @Override
123 public ComponentNode getModifiedConfigurationData() {
124 throw new ImmutableStateException("deprecated data") ;
125 }
126
127 public GhostSubsystemDescription getSubsystemDesc() {
128 return subsystemDesc;
129 }
130
131 void setSubsystemDesc(GhostSubsystemDescription subsystemDesc) {
132 this.subsystemDesc = subsystemDesc;
133 }
134
135 public Set<PastParameterConfiguration> getParameterConfigurations() {
136 return parameterConfigurations;
137 }
138
139 void setParameterConfigurations(Set<PastParameterConfiguration> parameterConfigurations) {
140 this.parameterConfigurations = Collections.unmodifiableSet(parameterConfigurations);
141 }
142
143
144
145 }