2 * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may
5 * not use this file except in compliance with the License. You may obtain
6 * a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 * implied. See the License for the specific language governing
14 * permissions and limitations under the License.
16 package org.akraino.validation.ui.entity;
18 import java.io.IOException;
19 import java.io.Serializable;
20 import java.util.HashSet;
23 import javax.persistence.CascadeType;
24 import javax.persistence.Column;
25 import javax.persistence.Entity;
26 import javax.persistence.FetchType;
27 import javax.persistence.GeneratedValue;
28 import javax.persistence.GenerationType;
29 import javax.persistence.Id;
30 import javax.persistence.JoinColumn;
31 import javax.persistence.JoinTable;
32 import javax.persistence.ManyToMany;
33 import javax.persistence.ManyToOne;
34 import javax.persistence.Table;
36 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
37 import org.onap.portalsdk.core.web.support.UserUtils;
39 import com.fasterxml.jackson.databind.SerializerProvider;
40 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
41 import com.fasterxml.jackson.databind.ser.std.StdSerializer;
44 @Table(name = "blueprint_instance")
45 public class BlueprintInstance implements Serializable {
47 private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(BlueprintInstance.class);
52 private static final long serialVersionUID = 1L;
55 @GeneratedValue(strategy = GenerationType.IDENTITY)
57 private int blueprintInstId;
60 @JoinColumn(name = "blueprint_id")
61 private Blueprint blueprint;
63 @Column(name = "version")
64 private String version;
66 @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
67 @JoinTable(name = "blueprint_instance_blueprint_layer", joinColumns = {
68 @JoinColumn(name = "blueprint_instance_id") }, inverseJoinColumns = {
69 @JoinColumn(name = "blueprint_layer_id") })
70 private Set<BlueprintLayer> blueprintLayers = new HashSet<>();
72 @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
73 @JoinTable(name = "blueprint_instance_timeslot", joinColumns = {
74 @JoinColumn(name = "blueprint_instance_id") }, inverseJoinColumns = { @JoinColumn(name = "timeslot_id") })
75 @JsonSerialize(using = TimeslotsSerializer.class)
76 private Set<Timeslot> timeslots = new HashSet<>();
78 public int getBlueprintInstanceId() {
79 return blueprintInstId;
82 public void setBlueprintInstanceId(int blueprintInstId) {
83 this.blueprintInstId = blueprintInstId;
86 public Blueprint getBlueprint() {
90 public void setBlueprint(Blueprint blueprint) {
91 this.blueprint = blueprint;
94 public void setVersion(String version) {
95 this.version = version;
98 public String getVersion() {
102 public Set<BlueprintLayer> getBlueprintLayers() {
103 return blueprintLayers;
106 public void setBlueprintLayers(Set<BlueprintLayer> blueprintLayers) {
107 this.blueprintLayers = blueprintLayers;
110 public Set<Timeslot> getTimeslots() {
114 public void setTimeslots(Set<Timeslot> timeslots) {
115 this.timeslots = timeslots;
118 static class TimeslotsSerializer extends StdSerializer<Set<Timeslot>> {
120 public TimeslotsSerializer() {
124 public TimeslotsSerializer(Class<Set<Timeslot>> tclass) {
129 public void serialize(Set<Timeslot> timeslots, com.fasterxml.jackson.core.JsonGenerator gen,
130 SerializerProvider provider) throws IOException {
131 Set<Timeslot> results = new HashSet<>();
132 for (Timeslot timeslot : timeslots) {
134 Timeslot result = new Timeslot();
135 result.setDuration(timeslot.getDuration());
136 result.setLabInfo(timeslot.getLabInfo());
137 result.setStartDateTime(timeslot.getStartDateTime());
138 result.setTimeslotId(timeslot.getTimeslotId());
140 } catch (Exception ex) {
141 LOGGER.error(EELFLoggerDelegate.errorLogger,
142 "Error when serializing." + UserUtils.getStackTrace(ex));
145 gen.writeObject(results);