From 9b33209bb00b0a97b0285275263bbbf0f9a7092b Mon Sep 17 00:00:00 2001
From: RIHTARSIC Joze <joze.rihtarsic@ext.ec.europa.eu>
Date: Sat, 17 Jun 2023 12:38:13 +0200
Subject: [PATCH] add Jaxb implementation

---
 pom.xml                                       | 15 +++++++++++---
 .../resource-details-panel.component.ts       | 16 +++++----------
 .../oasis-cppa3-spi/pom.xml                   |  4 ++--
 .../ec/smp/spi/handler/AbstractHandler.java   | 20 +++++++++----------
 smp-webapp/pom.xml                            |  9 ++++++++-
 .../services/javax.xml.bind.JAXBContext       |  1 +
 .../src/main/webapp/WEB-INF/weblogic.xml      |  1 +
 7 files changed, 38 insertions(+), 28 deletions(-)
 create mode 100644 smp-webapp/src/main/resources/META-INF/services/javax.xml.bind.JAXBContext

diff --git a/pom.xml b/pom.xml
index ea1d8e521..24c2172ec 100644
--- a/pom.xml
+++ b/pom.xml
@@ -67,9 +67,9 @@
         <javaee-api.version>7.0</javaee-api.version>
         <javax.annotation.version>1.3.2</javax.annotation.version>
         <javax.mail.version>1.6.2</javax.mail.version>
-        <jaxb.version>2.3.0.1</jaxb.version>
-        <jaxb-api.version>2.3.1</jaxb-api.version>
         <jaxb2-basics.version>1.11.1</jaxb2-basics.version>
+        <org.glassfish.jaxb.jaxb-runtime.version>2.3.8</org.glassfish.jaxb.jaxb-runtime.version>
+        <jakarta.xml.bind-api.version>2.3.3</jakarta.xml.bind-api.version>
         <jstl.version>1.2</jstl.version>
         <junit.version>4.13.2</junit.version>
         <junit-jupiter.version>5.9.2</junit-jupiter.version>
@@ -213,7 +213,16 @@
                 <artifactId>cxf-rt-features-logging</artifactId>
                 <version>${cxf.version}</version>
             </dependency>
-
+            <dependency>
+                <groupId>jakarta.xml.bind</groupId>
+                <artifactId>jakarta.xml.bind-api</artifactId>
+                <version>${jakarta.xml.bind-api.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.glassfish.jaxb</groupId>
+                <artifactId>jaxb-runtime</artifactId>
+                <version>${org.glassfish.jaxb.jaxb-runtime.version}</version>
+            </dependency>
             <dependency>
                 <groupId>org.apache.httpcomponents</groupId>
                 <artifactId>httpclient</artifactId>
diff --git a/smp-angular/src/app/edit/edit-resources/resource-details-panel/resource-details-panel.component.ts b/smp-angular/src/app/edit/edit-resources/resource-details-panel/resource-details-panel.component.ts
index 3b140de79..f0804d204 100644
--- a/smp-angular/src/app/edit/edit-resources/resource-details-panel/resource-details-panel.component.ts
+++ b/smp-angular/src/app/edit/edit-resources/resource-details-panel/resource-details-panel.component.ts
@@ -74,16 +74,16 @@ export class ResourceDetailsPanelComponent implements BeforeLeaveGuard {
     this.resourceForm.markAsPristine();
   }
 
-  onShowButtonDocumentClicked(){
+  onShowButtonDocumentClicked() {
     // set selected resource
     this.editResourceService.selectedResource = this.resource;
 
-    let node:NavigationNode = this.createNew();
+    let node: NavigationNode = this.createNew();
     this.navigationService.selected.children = [node]
     this.navigationService.select(node);
   }
 
-  public createNew():NavigationNode{
+  public createNew(): NavigationNode {
     return {
       code: "resource-document",
       icon: "note",
@@ -104,17 +104,11 @@ export class ResourceDetailsPanelComponent implements BeforeLeaveGuard {
       return "The private resource is accessible only to the resource members!"
     }
     if (this.group.visibility == VisibilityEnum.Private) {
-      return "The resource belongs to the private group. The resource is accessible only to the members of the group (direct and indirect group members)!"
+      return "The resource belongs to the private group. Only the group members and group resource members can access the resource!"
     }
     if (this.domain.visibility == VisibilityEnum.Private) {
-      return "The resource belongs to the private domain. The resource is accessible only to the members of the domain (direct and indirect domain members)!"
+      return "The resource belongs to the private domain. Only the domain members, domain group members and its resource members can access the resource!"
     }
     return "The resource is public on the public group and the public domain. The resource data is accessible to all users."
   }
 }
-
-
-
-
-
-
diff --git a/smp-resource-extensions/oasis-cppa3-spi/pom.xml b/smp-resource-extensions/oasis-cppa3-spi/pom.xml
index 3856fe473..4f124e270 100644
--- a/smp-resource-extensions/oasis-cppa3-spi/pom.xml
+++ b/smp-resource-extensions/oasis-cppa3-spi/pom.xml
@@ -22,8 +22,8 @@
     </parent>
     <properties>
         <maven.deploy.skip>false</maven.deploy.skip>
-        <jaxb-api.version>2.3.1</jaxb-api.version>
         <org.glassfish.jaxb.jaxb-runtime.version>2.3.8</org.glassfish.jaxb.jaxb-runtime.version>
+        <jakarta.xml.bind-api.version>2.3.3</jakarta.xml.bind-api.version>
     </properties>
     <artifactId>oasis-cppa3-spi</artifactId>
     <name>oasis-cppa3-spi</name>
@@ -102,7 +102,7 @@
         <dependency>
             <groupId>jakarta.xml.bind</groupId>
             <artifactId>jakarta.xml.bind-api</artifactId>
-            <version>2.3.3</version>
+            <version>${jakarta.xml.bind-api.version}</version>
         </dependency>
         <dependency>
             <groupId>org.glassfish.jaxb</groupId>
diff --git a/smp-resource-extensions/oasis-cppa3-spi/src/main/java/eu/europa/ec/smp/spi/handler/AbstractHandler.java b/smp-resource-extensions/oasis-cppa3-spi/src/main/java/eu/europa/ec/smp/spi/handler/AbstractHandler.java
index 796c7dbcb..d59ecc249 100644
--- a/smp-resource-extensions/oasis-cppa3-spi/src/main/java/eu/europa/ec/smp/spi/handler/AbstractHandler.java
+++ b/smp-resource-extensions/oasis-cppa3-spi/src/main/java/eu/europa/ec/smp/spi/handler/AbstractHandler.java
@@ -5,7 +5,6 @@ import eu.europa.ec.smp.spi.api.model.ResourceIdentifier;
 import eu.europa.ec.smp.spi.exceptions.CPPARuntimeException;
 import eu.europa.ec.smp.spi.exceptions.ResourceException;
 import eu.europa.ec.smp.spi.resource.ResourceHandlerSpi;
-
 import gen.eu.europa.ec.ddc.api.cppa.CPP;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.exception.ExceptionUtils;
@@ -67,7 +66,7 @@ public abstract class AbstractHandler implements ResourceHandlerSpi {
             JAXBContext jaxbContext = JAXBContext.newInstance(CPP.class);
             return jaxbContext.createUnmarshaller();
         } catch (JAXBException ex) {
-            LOG.error("Error occurred while initializing JAXBContext for ServiceGroup. Cause message:" +  ex, ex);
+            LOG.error("Error occurred while initializing JAXBContext for ServiceGroup. Cause message:" + ex, ex);
         }
         return null;
     });
@@ -78,7 +77,7 @@ public abstract class AbstractHandler implements ResourceHandlerSpi {
             JAXBContext jaxbContext = JAXBContext.newInstance(CPP.class);
             return jaxbContext.createMarshaller();
         } catch (JAXBException ex) {
-            LOG.error("Error occurred while initializing JAXBContext for ServiceGroup. Cause message:" +  ex, ex);
+            LOG.error("Error occurred while initializing JAXBContext for ServiceGroup. Cause message:" + ex, ex);
         }
         return null;
     });
@@ -99,6 +98,7 @@ public abstract class AbstractHandler implements ResourceHandlerSpi {
     public Marshaller getMarshaller() {
         return jaxbMarshaller.get();
     }
+
     /**
      * Removes the current thread's ServiceGroup Unmarshaller for this thread-local variable. If this thread-local variable
      * is subsequently read by the current thread, its value will be reinitialized by invoking its initialValue method.
@@ -147,14 +147,14 @@ public abstract class AbstractHandler implements ResourceHandlerSpi {
 
     public CPP parseNative(Document document) {
         try {
-            return  (CPP)jaxbUnmarshaller.get().unmarshal(document);
+            return (CPP) jaxbUnmarshaller.get().unmarshal(document);
         } catch (JAXBException ex) {
             throw new CPPARuntimeException(CPPARuntimeException.ErrorCode.PARSE_ERROR, "Can not parse XML Document ! Error: [" + ExceptionUtils.getRootCauseMessage(ex) + "]", ex);
         }
     }
 
 
-    public CPP parseNative(InputStream inputStream)  {
+    public CPP parseNative(InputStream inputStream) {
         try {
             DocumentBuilder db = createDocumentBuilder();
             // just to validate DISALLOW_DOCTYPE_FEATURE parse to Document
@@ -171,11 +171,12 @@ public abstract class AbstractHandler implements ResourceHandlerSpi {
             return;
         }
         Marshaller jaxbMarshaller = getMarshaller();
+
         // Pretty Print XML
         try {
-            if (prettyPrint) {
-                jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, prettyPrint);
-            }
+            jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
+            jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, prettyPrint ? Boolean.TRUE : Boolean.FALSE);
+
             // to remove xmlDeclaration
             jaxbMarshaller.marshal(jaxbObject, outputStream);
         } catch (JAXBException ex) {
@@ -188,8 +189,6 @@ public abstract class AbstractHandler implements ResourceHandlerSpi {
     }
 
 
-
-
     public QName getRootElementQName(Document document) {
         Element element = document.getDocumentElement();
         String namespace = element.getNamespaceURI();
@@ -197,7 +196,6 @@ public abstract class AbstractHandler implements ResourceHandlerSpi {
     }
 
 
-
     public ResourceIdentifier getResourceIdentifier(RequestData resourceData) throws ResourceException {
         if (resourceData == null || resourceData.getResourceIdentifier() == null || StringUtils.isEmpty(resourceData.getResourceIdentifier().getValue())) {
             throw new ResourceException(ResourceException.ErrorCode.INVALID_PARAMETERS, "Missing resource identifier for the resource CPP ");
diff --git a/smp-webapp/pom.xml b/smp-webapp/pom.xml
index e2fdd3a29..9e092a6b7 100644
--- a/smp-webapp/pom.xml
+++ b/smp-webapp/pom.xml
@@ -39,7 +39,14 @@
             <artifactId>oasis-cppa3-spi</artifactId>
             <version>${project.version}</version>
         </dependency>
-
+        <dependency>
+            <groupId>jakarta.xml.bind</groupId>
+            <artifactId>jakarta.xml.bind-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.glassfish.jaxb</groupId>
+            <artifactId>jaxb-runtime</artifactId>
+        </dependency>
         <dependency>
             <groupId>eu.europa.ec.dynamic-discovery</groupId>
             <artifactId>dynamic-discovery-client</artifactId>
diff --git a/smp-webapp/src/main/resources/META-INF/services/javax.xml.bind.JAXBContext b/smp-webapp/src/main/resources/META-INF/services/javax.xml.bind.JAXBContext
new file mode 100644
index 000000000..f874da560
--- /dev/null
+++ b/smp-webapp/src/main/resources/META-INF/services/javax.xml.bind.JAXBContext
@@ -0,0 +1 @@
+com.sun.xml.bind.v2.ContextFactory
\ No newline at end of file
diff --git a/smp-webapp/src/main/webapp/WEB-INF/weblogic.xml b/smp-webapp/src/main/webapp/WEB-INF/weblogic.xml
index 4d297cdda..c0482ea28 100644
--- a/smp-webapp/src/main/webapp/WEB-INF/weblogic.xml
+++ b/smp-webapp/src/main/webapp/WEB-INF/weblogic.xml
@@ -34,6 +34,7 @@
         </prefer-application-packages>
         <prefer-application-resources>
             <resource-name>org/slf4j/impl/StaticLoggerBinder.class</resource-name>
+            <resource-name>META-INF/services/javax.xml.bind.JAXBContext</resource-name>
         </prefer-application-resources>
     </container-descriptor>
 </weblogic-web-app>
-- 
GitLab