*/
package org.akraino.validation.ui.entity;
+import java.io.IOException;
import java.io.Serializable;
+import java.util.HashSet;
+import java.util.Set;
+import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
+import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
+import javax.persistence.JoinTable;
+import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
-import javax.persistence.OneToOne;
-import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
-import org.akraino.validation.ui.data.BlueprintLayer;
+import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.onap.portalsdk.core.web.support.UserUtils;
+
+import com.fasterxml.jackson.databind.SerializerProvider;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.StdSerializer;
@Entity
-@Table(name = "akraino.blueprint_instance")
+@Table(name = "blueprint_instance")
public class BlueprintInstance implements Serializable {
+ private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(BlueprintInstance.class);
+
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
- @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "blueprint_instance_id_generator")
- @SequenceGenerator(name = "blueprint_instance_id_generator", sequenceName = "akraino.seq_blueprint_instance",
- allocationSize = 1)
- @Column(name = "blueprint_instance_id")
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ @Column(name = "id")
private int blueprintInstId;
@ManyToOne
@Column(name = "version")
private String version;
- @Column(name = "layer")
- private BlueprintLayer layer;
-
- @Column(name = "layer_description")
- private String layerDescription;
+ @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
+ @JoinTable(name = "blueprint_instance_blueprint_layer", joinColumns = {
+ @JoinColumn(name = "blueprint_instance_id") }, inverseJoinColumns = {
+ @JoinColumn(name = "blueprint_layer_id") })
+ private Set<BlueprintLayer> blueprintLayers = new HashSet<>();
- @OneToOne
- @JoinColumn(name = "timeslot_id")
- private Timeslot timeslot;
+ @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
+ @JoinTable(name = "blueprint_instance_timeslot", joinColumns = {
+ @JoinColumn(name = "blueprint_instance_id") }, inverseJoinColumns = { @JoinColumn(name = "timeslot_id") })
+ @JsonSerialize(using = TimeslotsSerializer.class)
+ private Set<Timeslot> timeslots = new HashSet<>();
public int getBlueprintInstanceId() {
return blueprintInstId;
return version;
}
- public BlueprintLayer getLayer() {
- return layer;
- }
-
- public void setLayer(BlueprintLayer layer) {
- this.layer = layer;
+ public Set<BlueprintLayer> getBlueprintLayers() {
+ return blueprintLayers;
}
- public void setLayerDescription(String layerDescription) {
- this.layerDescription = layerDescription;
+ public void setBlueprintLayers(Set<BlueprintLayer> blueprintLayers) {
+ this.blueprintLayers = blueprintLayers;
}
- public String getLayerDescription() {
- return layerDescription;
+ public Set<Timeslot> getTimeslots() {
+ return timeslots;
}
- public void setTimeslot(Timeslot timeslot) {
- this.timeslot = timeslot;
+ public void setTimeslots(Set<Timeslot> timeslots) {
+ this.timeslots = timeslots;
}
- public Timeslot getTimeslot() {
- return this.timeslot;
+ static class TimeslotsSerializer extends StdSerializer<Set<Timeslot>> {
+
+ public TimeslotsSerializer() {
+ this(null);
+ }
+
+ public TimeslotsSerializer(Class<Set<Timeslot>> tclass) {
+ super(tclass);
+ }
+
+ @Override
+ public void serialize(Set<Timeslot> timeslots, com.fasterxml.jackson.core.JsonGenerator gen,
+ SerializerProvider provider) throws IOException {
+ Set<Timeslot> results = new HashSet<>();
+ for (Timeslot timeslot : timeslots) {
+ try {
+ Timeslot result = new Timeslot();
+ result.setDuration(timeslot.getDuration());
+ result.setLabInfo(timeslot.getLabInfo());
+ result.setStartDateTime(timeslot.getStartDateTime());
+ result.setTimeslotId(timeslot.getTimeslotId());
+ results.add(result);
+ } catch (Exception ex) {
+ LOGGER.error(EELFLoggerDelegate.errorLogger,
+ "Error when serializing." + UserUtils.getStackTrace(ex));
+ }
+ }
+ gen.writeObject(results);
+ }
}
}