From f64d9a86ad00d1a9117ddda5d1757d7e2b87401c Mon Sep 17 00:00:00 2001 From: Bojnourdi Date: Fri, 14 Aug 2015 12:16:22 +0200 Subject: [PATCH] Working on Profile --- .../java/com/edf/gde/entities/Profile.java | 36 ++++++++++++++++++- .../edf/gde/entities/ProfileAttribute.java | 10 ++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/Profile.java b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/Profile.java index 0e9affd..21f1fad 100644 --- a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/Profile.java +++ b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/Profile.java @@ -3,13 +3,19 @@ */ package com.edf.gde.entities; +import com.edf.gde.transferables.AttributeTO; +import com.edf.gde.transferables.ProfileAttributeTO; +import com.edf.gde.transferables.ProfileTO; import java.io.Serializable; +import java.util.ArrayList; import java.util.Collection; +import java.util.List; import java.util.Objects; import javax.persistence.Basic; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.EntityManager; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; @@ -82,7 +88,6 @@ public class Profile implements Serializable { this.name = name; } - @XmlTransient public Collection getProfileAttributeCollection() { return profileAttributeCollection; } @@ -91,6 +96,35 @@ public class Profile implements Serializable { this.profileAttributeCollection = profileAttributeCollection; } + public static Profile fromProtileTO(EntityManager em, ProfileTO profileTO) { + Profile profile = new Profile(); + profile.setId(profileTO.getId()); + profile.setName(profileTO.getName()); + List attributeTOs = profileTO.getAttributes(); + if (attributeTOs != null) { + List attributes = new ArrayList<>(); + for (ProfileAttributeTO ato : attributeTOs) { + attributes.add(ProfileAttribute.fromProfileAttributeTO(em, ato)); + } + profile.setProfileAttributeCollection(attributes); + } + return profile; + } + + public ProfileTO toProfileTO() { + ProfileTO profileTO = new ProfileTO(); + profileTO.setId(id); + profileTO.setName(name); + if (profileAttributeCollection != null) { + List attributeTOs = new ArrayList<>(); + for (ProfileAttribute attribute : profileAttributeCollection) { + attributeTOs.add(attribute.toProfileAttributeTO()); + } + profileTO.setAttributes(attributeTOs); + } + return profileTO; + } + @Override public String toString() { return "com.edf.gde.entities.Profile[ id=" + id + " ]"; diff --git a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/ProfileAttribute.java b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/ProfileAttribute.java index 3a90e3d..4ee3f2f 100644 --- a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/ProfileAttribute.java +++ b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/ProfileAttribute.java @@ -114,6 +114,16 @@ public class ProfileAttribute implements Serializable { return attribute; } + public ProfileAttributeTO toProfileAttributeTO() { + ProfileAttributeTO attributeTO = new ProfileAttributeTO(); + attributeTO.setId(id); + attributeTO.setMandatory(mandatory); + attributeTO.setName(name); + attributeTO.setType(type); + attributeTO.setProfileId(profile==null ? 0:profile.getId()); + return attributeTO; + } + @Override public String toString() { return "com.edf.gde.entities.ProfileAttribute[ id=" + id + " ]"; -- 2.39.2