Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit 412fcb32 authored by Pawel GUTOWSKI's avatar Pawel GUTOWSKI
Browse files

EDELIVERY-2259 Refactored DAO layer and data model

parent 6553a8ee
No related branches found
No related tags found
No related merge requests found
Showing
with 395 additions and 615 deletions
......@@ -18,7 +18,6 @@ import eu.europa.ec.cipa.smp.server.util.to_be_removed.ESuccess;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nonnull;
import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
......@@ -79,7 +78,7 @@ public final class PostRegistrationFilter implements Filter {
public void init (final FilterConfig arg0) {}
private static void _notifyRegistrationHook (@Nonnull final ESuccess eSuccess) throws ServletException {
private static void _notifyRegistrationHook (final ESuccess eSuccess) throws ServletException {
final AbstractRegistrationHook aCallback = AbstractRegistrationHook.getQueue ();
if (aCallback != null) {
try {
......
......@@ -136,25 +136,8 @@ public final class KeyStoreUtils {
aKeyStore.load (aIS, aKeyStorePassword);
return aKeyStore;
}finally {
//if(aIS != null){
aIS.close();
//}
}
/*
catch (final IOException e) {
StreamUtils.close (aIS);
aIS = ClassPathResource.getInputStream (sKeyStorePath);
if (aIS == null) {
// Fallback to file system - maybe this helps...
aIS = new FileSystemResource (sKeyStorePath).getInputStream ();
}
}*/
// } catch (final KeyStoreException ex) {
// throw new
// IllegalStateException("No provider can handle JKS key stores! Very weird!",
// ex);
// }
}
throw new IllegalStateException ("No provider can handle JKS key stores! Very weird!");
}
......@@ -190,8 +173,6 @@ public final class KeyStoreUtils {
@Nonnull final String sAliasToCopy,
@Nullable final char [] aAliasPassword) throws GeneralSecurityException,
IOException {
/*ValueEnforcer.notNull (aBaseKeyStore, "BaseKeyStore");
ValueEnforcer.notNull (sAliasToCopy, "AliasToCopy");*/
final KeyStore aKeyStore = KeyStore.getInstance (aBaseKeyStore.getType (), aBaseKeyStore.getProvider ());
// null stream means: create new key store
......
......@@ -17,7 +17,6 @@ package eu.europa.ec.edelivery.smp.data.dao;
import eu.europa.ec.edelivery.smp.data.model.DBServiceGroup;
import eu.europa.ec.edelivery.smp.data.model.DBServiceGroupID;
import org.oasis_open.docs.bdxr.ns.smp._2016._05.ParticipantIdentifierType;
import org.springframework.stereotype.Repository;
import javax.persistence.EntityManager;
......@@ -32,21 +31,15 @@ public class ServiceGroupDao {
@PersistenceContext
EntityManager entityManager;
public DBServiceGroup find(ParticipantIdentifierType serviceGroupId) {
DBServiceGroupID dbServiceGroupId = new DBServiceGroupID(serviceGroupId);
return entityManager.find(DBServiceGroup.class, dbServiceGroupId);
}
public DBServiceGroup find(String participantIdScheme,
String participantIdValue) {
public void update(DBServiceGroup dbServiceGroup) {
//TODO Try to use one method for both create and update
entityManager.merge(dbServiceGroup);
DBServiceGroupID dbServiceGroupId = new DBServiceGroupID(participantIdScheme, participantIdValue);
return entityManager.find(DBServiceGroup.class, dbServiceGroupId);
}
public void save(DBServiceGroup dbServiceGroup) {
//TODO Try to use one method for both create and update
entityManager.persist(dbServiceGroup);
/*entityManager.flush();
System.out.print("====DUPA");*/
}
public void remove(DBServiceGroup serviceGroup) {
......
......@@ -17,13 +17,10 @@ package eu.europa.ec.edelivery.smp.data.dao;
import eu.europa.ec.edelivery.smp.data.model.DBServiceMetadata;
import eu.europa.ec.edelivery.smp.data.model.DBServiceMetadataID;
import org.oasis_open.docs.bdxr.ns.smp._2016._05.DocumentIdentifier;
import org.oasis_open.docs.bdxr.ns.smp._2016._05.ParticipantIdentifierType;
import org.springframework.stereotype.Repository;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -35,9 +32,17 @@ public class ServiceMetadataDao {
@PersistenceContext
EntityManager entityManager;
public DBServiceMetadata find(ParticipantIdentifierType serviceGroupId, DocumentIdentifier documentId) {
DBServiceMetadataID aDBServiceMetadataID = new DBServiceMetadataID(serviceGroupId, documentId);
return entityManager.find(DBServiceMetadata.class, aDBServiceMetadataID);
public DBServiceMetadata find(String participantIdScheme,
String participantIdValue,
String documentIdScheme,
String documentIdValue) {
DBServiceMetadataID serviceMetadataId = new DBServiceMetadataID(participantIdScheme,
participantIdValue,
documentIdScheme,
documentIdValue);
return entityManager.find(DBServiceMetadata.class, serviceMetadataId);
}
/**
......@@ -46,8 +51,16 @@ public class ServiceMetadataDao {
* @return true if entity existed before and was removed in this call.
* False if entity did not exist, so nothing was changed
*/
public boolean remove(ParticipantIdentifierType serviceGroupId, DocumentIdentifier documentId) {
DBServiceMetadata serviceMetadata = find(serviceGroupId, documentId);
public boolean remove(String participantIdScheme,
String participantIdValue,
String documentIdScheme,
String documentIdValue) {
DBServiceMetadata serviceMetadata = find(participantIdScheme,
participantIdValue,
documentIdScheme,
documentIdValue);
if (serviceMetadata == null) {
return false;
}
......@@ -59,17 +72,12 @@ public class ServiceMetadataDao {
entityManager.persist(serviceMetadata);
}
public List<DBServiceMetadataID> findIdsByServiceGroup(ParticipantIdentifierType serviceGroupId) {
//TODO Check if you can retrieve IDs directly
List<DBServiceMetadata> aServices = entityManager.createQuery("SELECT p FROM DBServiceMetadata p WHERE p.id.businessIdentifierScheme = :scheme AND p.id.businessIdentifier = :value", DBServiceMetadata.class)
.setParameter("scheme", serviceGroupId.getScheme())
.setParameter("value", serviceGroupId.getValue())
.getResultList();
public List<DBServiceMetadataID> findIdsByServiceGroup(String participantIdScheme,
String participantIdValue) {
final List<DBServiceMetadataID> serviceMetadataIds = new ArrayList<>();
for (final DBServiceMetadata aService : aServices) {
serviceMetadataIds.add(aService.getId());
}
return serviceMetadataIds;
return entityManager.createQuery("SELECT p.id FROM DBServiceMetadata p WHERE p.id.businessIdentifierScheme = :scheme AND p.id.businessIdentifier = :value", DBServiceMetadataID.class)
.setParameter("scheme", participantIdScheme)
.setParameter("value", participantIdValue)
.getResultList();
}
}
......@@ -13,21 +13,6 @@
* See the Licence for the specific language governing permissions and limitations under the Licence.
*/
/*
* Copyright 2017 European Commission | CEF eDelivery
*
* Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence");
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* or file: LICENCE-EUPL-v1.1.pdf
*
* Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and limitations under the Licence.
*/
package eu.europa.ec.edelivery.smp.data.model;
/**
......@@ -37,5 +22,6 @@ public class CommonColumnsLengths {
public static final int MAX_IDENTIFIER_SCHEME_LENGTH = 100;
public static final int MAX_PARTICIPANT_IDENTIFIER_VALUE_LENGTH = 50;
public static final int MAX_DOCUMENT_TYPE_IDENTIFIER_VALUE_LENGTH = 500;
public static final int MAX_USERNAME_LENGTH = 256;
public static final String URL_SCHEME_VALUE_SEPARATOR = "::";
}
......@@ -13,63 +13,36 @@
* See the Licence for the specific language governing permissions and limitations under the Licence.
*/
/*
* Copyright 2017 European Commission | CEF eDelivery
*
* Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence");
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* or file: LICENCE-EUPL-v1.1.pdf
*
* Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and limitations under the Licence.
*/
package eu.europa.ec.edelivery.smp.data.model;
import javax.persistence.*;
import java.io.Serializable;
/**
* Define the ownership of a service group -&gt; relates DB user to DB service
* group.
*
* @author PEPPOL.AT, BRZ, Philip Helger
*/
@Entity
@Table (name = "smp_ownership")
public class DBOwnership implements Serializable {
private DBOwnershipID m_aID;
private DBUser m_aUser;
private DBServiceGroup m_aServiceGroup;
private DBOwnershipID ownershipId;
private DBUser user;
private DBServiceGroup serviceGroup;
public DBOwnership () {}
public DBOwnership (final DBOwnershipID aID, final DBUser aUser, final DBServiceGroup aServiceGroup) {
m_aID = aID;
m_aUser = aUser;
m_aServiceGroup = aServiceGroup;
public DBOwnership (final DBOwnershipID ownershipId, final DBUser user, final DBServiceGroup serviceGroup) {
this.ownershipId = ownershipId;
this.user = user;
this.serviceGroup = serviceGroup;
}
@EmbeddedId
public DBOwnershipID getId () {
return m_aID;
}
public void setId (final DBOwnershipID aID) {
m_aID = aID;
return ownershipId;
}
@ManyToOne (fetch = FetchType.LAZY)
@JoinColumn (name = "username", nullable = false, insertable = false, updatable = false)
public DBUser getUser () {
return m_aUser;
}
public void setUser (final DBUser aUser) {
m_aUser = aUser;
return user;
}
@ManyToOne (fetch = FetchType.LAZY)
......@@ -84,10 +57,18 @@ public class DBOwnership implements Serializable {
insertable = false,
updatable = false) })
public DBServiceGroup getServiceGroup () {
return m_aServiceGroup;
return serviceGroup;
}
public void setId (final DBOwnershipID ownershipId) {
this.ownershipId = ownershipId;
}
public void setUser (final DBUser user) {
this.user = user;
}
public void setServiceGroup (final DBServiceGroup aServiceGroup) {
m_aServiceGroup = aServiceGroup;
public void setServiceGroup (final DBServiceGroup serviceGroup) {
this.serviceGroup = serviceGroup;
}
}
......@@ -13,89 +13,58 @@
* See the Licence for the specific language governing permissions and limitations under the Licence.
*/
/*
* Copyright 2017 European Commission | CEF eDelivery
*
* Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence");
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* or file: LICENCE-EUPL-v1.1.pdf
*
* Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and limitations under the Licence.
*/
package eu.europa.ec.edelivery.smp.data.model;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.oasis_open.docs.bdxr.ns.smp._2016._05.ParticipantIdentifierType;
import javax.annotation.Nonnull;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.Transient;
import java.io.Serializable;
/**
* ID for the ownership
*
* @author PEPPOL.AT, BRZ, Philip Helger
*/
@Embeddable
@ToString
@EqualsAndHashCode
public class DBOwnershipID implements Serializable {
private String m_sUsername;
private String m_sParticipantIdentifierScheme;
private String m_sParticipantIdentifier;
@Deprecated
public DBOwnershipID () {}
public DBOwnershipID (final String sUserName, @Nonnull final ParticipantIdentifierType aBusinessIdentifier) {
m_sUsername = sUserName;
setBusinessIdentifier (aBusinessIdentifier);
}
private String username;
private String participantIdScheme;
private String participantIdValue;
@Column (name = "username", nullable = false, length = 256)
public String getUsername () {
return m_sUsername;
}
@Deprecated
public DBOwnershipID() {
}
public void setUsername (final String sUserName) {
m_sUsername = sUserName;
}
public DBOwnershipID(String userName, String participantIdScheme, String participantIdValue) {
username = userName;
setBusinessIdentifierScheme(participantIdScheme);
setBusinessIdentifier(participantIdValue);
}
@Column (name = "businessIdentifierScheme", nullable = false, length = CommonColumnsLengths.MAX_IDENTIFIER_SCHEME_LENGTH)
public String getBusinessIdentifierScheme () {
return m_sParticipantIdentifierScheme;
}
@Column(name = "username", nullable = false, length = 256)
public String getUsername() {
return username;
}
public void setBusinessIdentifierScheme (final String sBusinessIdentifierScheme) {
m_sParticipantIdentifierScheme = sBusinessIdentifierScheme;
}
@Column(name = "businessIdentifierScheme", nullable = false, length = CommonColumnsLengths.MAX_IDENTIFIER_SCHEME_LENGTH)
public String getBusinessIdentifierScheme() {
return participantIdScheme;
}
@Column (name = "businessIdentifier", nullable = false, length = CommonColumnsLengths.MAX_PARTICIPANT_IDENTIFIER_VALUE_LENGTH)
public String getBusinessIdentifier () {
return m_sParticipantIdentifier;
}
@Column(name = "businessIdentifier", nullable = false, length = CommonColumnsLengths.MAX_PARTICIPANT_IDENTIFIER_VALUE_LENGTH)
public String getBusinessIdentifier() {
return participantIdValue;
}
public void setBusinessIdentifier (final String sBusinessIdentifier) {
m_sParticipantIdentifier = sBusinessIdentifier;
}
public void setUsername(final String sUserName) {
username = sUserName;
}
@Transient
public void setBusinessIdentifier (@Nonnull final ParticipantIdentifierType aPI) {
setBusinessIdentifierScheme (aPI.getScheme ());
setBusinessIdentifier (aPI.getValue ());
}
public void setBusinessIdentifierScheme(final String sBusinessIdentifierScheme) {
participantIdScheme = sBusinessIdentifierScheme;
}
@Transient
@Nonnull
public ParticipantIdentifierType asBusinessIdentifier () {
return new ParticipantIdentifierType(m_sParticipantIdentifierScheme, m_sParticipantIdentifier);
}
public void setBusinessIdentifier(final String sBusinessIdentifier) {
participantIdValue = sBusinessIdentifier;
}
}
......@@ -13,92 +13,74 @@
* See the Licence for the specific language governing permissions and limitations under the Licence.
*/
/*
* Copyright 2017 European Commission | CEF eDelivery
*
* Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence");
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* or file: LICENCE-EUPL-v1.1.pdf
*
* Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and limitations under the Licence.
*/
package eu.europa.ec.edelivery.smp.data.model;
import javax.annotation.Nullable;
import javax.persistence.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
/**
* ServiceGroup generated by hbm2java
*
* @author PEPPOL.AT, BRZ, Philip Helger
*/
@Entity
@Table (name = "smp_service_group")
@Table(name = "smp_service_group")
public class DBServiceGroup implements Serializable {
private DBServiceGroupID m_aID;
private String m_sExtension;
private Set <DBOwnership> m_aOwnerships = new HashSet <DBOwnership> ();
private Set <DBServiceMetadata> m_aServiceMetadatas = new HashSet <DBServiceMetadata> ();
public DBServiceGroup () {}
public DBServiceGroup (final DBServiceGroupID aID) {
m_aID = aID;
}
public DBServiceGroup (final DBServiceGroupID aID,
final String sExtension,
final Set <DBOwnership> aOwnerships,
final Set <DBServiceMetadata> aServiceMetadatas) {
m_aID = aID;
m_sExtension = sExtension;
m_aOwnerships = aOwnerships;
m_aServiceMetadatas = aServiceMetadatas;
}
@EmbeddedId
public DBServiceGroupID getId () {
return m_aID;
}
public void setId (final DBServiceGroupID aID) {
m_aID = aID;
}
@Lob
@Column (name = "extension", length = 65535)
public String getExtension () {
return m_sExtension;
}
public void setExtension (@Nullable final String sExtension) {
m_sExtension = sExtension;
}
@OneToMany (fetch = FetchType.LAZY, mappedBy = "serviceGroup", cascade = { CascadeType.ALL })
public Set <DBOwnership> getOwnerships () {
return m_aOwnerships;
}
public void setOwnerships (final Set <DBOwnership> aOwnerships) {
m_aOwnerships = aOwnerships;
}
@OneToMany (fetch = FetchType.LAZY, mappedBy = "serviceGroup", cascade = { CascadeType.ALL })
public Set <DBServiceMetadata> getServiceMetadatas () {
return m_aServiceMetadatas;
}
public void setServiceMetadatas (final Set <DBServiceMetadata> aServiceMetadatas) {
m_aServiceMetadatas = aServiceMetadatas;
}
private DBServiceGroupID serviceGroupId;
private String extension;
private Set<DBOwnership> ownerships = new HashSet<>();
private Set<DBServiceMetadata> serviceMetadatas = new HashSet<DBServiceMetadata>();
public DBServiceGroup() {
}
public DBServiceGroup(final DBServiceGroupID serviceGroupId) {
this.serviceGroupId = serviceGroupId;
}
public DBServiceGroup(final DBServiceGroupID serviceGroupId,
final String extension,
final Set<DBOwnership> ownerships,
final Set<DBServiceMetadata> serviceMetadatas) {
this.serviceGroupId = serviceGroupId;
this.extension = extension;
this.ownerships = ownerships;
this.serviceMetadatas = serviceMetadatas;
}
@EmbeddedId
public DBServiceGroupID getId() {
return serviceGroupId;
}
@Lob
@Column(name = "extension", length = 65535)
public String getExtension() {
return extension;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "serviceGroup", cascade = {CascadeType.ALL})
public Set<DBOwnership> getOwnerships() {
return ownerships;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "serviceGroup", cascade = {CascadeType.ALL})
public Set<DBServiceMetadata> getServiceMetadatas() {
return serviceMetadatas;
}
public void setId(final DBServiceGroupID serviceGroupId) {
this.serviceGroupId = serviceGroupId;
}
public void setExtension(String extensions) {
this.extension = extensions;
}
public void setOwnerships(final Set<DBOwnership> ownerships) {
this.ownerships = ownerships;
}
public void setServiceMetadatas(final Set<DBServiceMetadata> serviceMetadatas) {
this.serviceMetadatas = serviceMetadatas;
}
}
......@@ -13,74 +13,53 @@
* See the Licence for the specific language governing permissions and limitations under the Licence.
*/
/*
* Copyright 2017 European Commission | CEF eDelivery
*
* Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence");
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* or file: LICENCE-EUPL-v1.1.pdf
*
* Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and limitations under the Licence.
*/
package eu.europa.ec.edelivery.smp.data.model;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.oasis_open.docs.bdxr.ns.smp._2016._05.ParticipantIdentifierType;
import javax.annotation.Nonnull;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.Transient;
import java.io.Serializable;
/**
* ServiceGroupId == participant ID
*
* @author PEPPOL.AT, BRZ, Philip Helger
*/
import static eu.europa.ec.edelivery.smp.data.model.CommonColumnsLengths.MAX_IDENTIFIER_SCHEME_LENGTH;
import static eu.europa.ec.edelivery.smp.data.model.CommonColumnsLengths.MAX_PARTICIPANT_IDENTIFIER_VALUE_LENGTH;
@Embeddable
@ToString
@EqualsAndHashCode
public class DBServiceGroupID implements Serializable {
private String m_sParticipantIdentifierScheme;
private String m_sParticipantIdentifier;
@Deprecated
public DBServiceGroupID () {}
private String participantIdScheme;
private String participantIdValue;
@Deprecated
public DBServiceGroupID() {
}
public DBServiceGroupID (@Nonnull final ParticipantIdentifierType aBusinessID) {
setBusinessIdentifierScheme (aBusinessID.getScheme ());
setBusinessIdentifier (aBusinessID.getValue ());
}
public DBServiceGroupID(String participantIdScheme,
String participantIdValue) {
@Column (name = "businessIdentifierScheme", nullable = false, length = CommonColumnsLengths.MAX_IDENTIFIER_SCHEME_LENGTH)
public String getBusinessIdentifierScheme () {
return m_sParticipantIdentifierScheme;
}
setBusinessIdentifierScheme(participantIdScheme);
setBusinessIdentifier(participantIdValue);
}
public void setBusinessIdentifierScheme (final String sBusinessIdentifierScheme) {
m_sParticipantIdentifierScheme = sBusinessIdentifierScheme;
}
@Column(name = "businessIdentifierScheme", nullable = false, length = MAX_IDENTIFIER_SCHEME_LENGTH)
public String getBusinessIdentifierScheme() {
return participantIdScheme;
}
@Column (name = "businessIdentifier", nullable = false, length = CommonColumnsLengths.MAX_PARTICIPANT_IDENTIFIER_VALUE_LENGTH)
public String getBusinessIdentifier () {
return m_sParticipantIdentifier;
}
@Column(name = "businessIdentifier", nullable = false, length = MAX_PARTICIPANT_IDENTIFIER_VALUE_LENGTH)
public String getBusinessIdentifier() {
return participantIdValue;
}
public void setBusinessIdentifier (final String sBusinessIdentifier) {
m_sParticipantIdentifier = sBusinessIdentifier;
}
public void setBusinessIdentifierScheme(String participantIdScheme) {
this.participantIdScheme = participantIdScheme;
}
@Transient
@Nonnull
public ParticipantIdentifierType asBusinessIdentifier() {
return new ParticipantIdentifierType(m_sParticipantIdentifier, m_sParticipantIdentifierScheme);
}
public void setBusinessIdentifier(String participantIdValue) {
this.participantIdValue = participantIdValue;
}
}
......@@ -13,93 +13,69 @@
* See the Licence for the specific language governing permissions and limitations under the Licence.
*/
/*
* Copyright 2017 European Commission | CEF eDelivery
*
* Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence");
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* or file: LICENCE-EUPL-v1.1.pdf
*
* Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and limitations under the Licence.
*/
package eu.europa.ec.edelivery.smp.data.model;
import javax.annotation.Nullable;
import javax.persistence.*;
import java.io.Serializable;
/**
* ServiceMetadata generated by hbm2java
*
* @author PEPPOL.AT, BRZ, Philip Helger
*/
@Entity
@Table (name = "smp_service_metadata")
@Table(name = "smp_service_metadata")
public class DBServiceMetadata implements Serializable {
private DBServiceMetadataID m_aID;
private DBServiceGroup m_aServiceGroup;
private String m_sExtension;
private String m_sXmlContent;
private DBServiceMetadataID serviceMetadataId;
private DBServiceGroup serviceGroup;
private String xmlContent;
public DBServiceMetadata () {}
public DBServiceMetadata() { }
public DBServiceMetadata (final DBServiceMetadataID aID, final DBServiceGroup aServiceGroup) {
m_aID = aID;
m_aServiceGroup = aServiceGroup;
}
public DBServiceMetadata(DBServiceMetadataID serviceMetadataId, DBServiceGroup serviceGroup) {
this(serviceMetadataId, serviceGroup, null);
}
public DBServiceMetadata (final DBServiceMetadataID aID,
final DBServiceGroup aServiceGroup,
final String sExtension,
final String sXmlContent) {
m_aID = aID;
m_aServiceGroup = aServiceGroup;
m_sExtension = sExtension;
m_sXmlContent = sXmlContent;
}
public DBServiceMetadata(DBServiceMetadataID serviceMetadataId,
DBServiceGroup serviceGroup,
String xmlContent) {
this.serviceMetadataId = serviceMetadataId;
this.serviceGroup = serviceGroup;
this.xmlContent = xmlContent;
}
@EmbeddedId
public DBServiceMetadataID getId () {
return m_aID;
}
@EmbeddedId
public DBServiceMetadataID getId() {
return serviceMetadataId;
}
public void setId (final DBServiceMetadataID aID) {
m_aID = aID;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({@JoinColumn(name = "businessIdentifier",
referencedColumnName = "businessIdentifier",
nullable = false,
insertable = false,
updatable = false),
@JoinColumn(name = "businessIdentifierScheme",
referencedColumnName = "businessIdentifierScheme",
nullable = false,
insertable = false,
updatable = false)})
public DBServiceGroup getServiceGroup() {
return serviceGroup;
}
@ManyToOne (fetch = FetchType.LAZY)
@JoinColumns ({ @JoinColumn (name = "businessIdentifier",
referencedColumnName = "businessIdentifier",
nullable = false,
insertable = false,
updatable = false),
@JoinColumn (name = "businessIdentifierScheme",
referencedColumnName = "businessIdentifierScheme",
nullable = false,
insertable = false,
updatable = false) })
public DBServiceGroup getServiceGroup () {
return m_aServiceGroup;
}
@Lob
@Column(name = "xmlcontent")
public String getXmlContent() {
return xmlContent;
}
public void setServiceGroup (final DBServiceGroup aServiceGroup) {
m_aServiceGroup = aServiceGroup;
}
public void setId(final DBServiceMetadataID serviceMetadataId) {
this.serviceMetadataId = serviceMetadataId;
}
@Lob
@Column(name = "xmlcontent")
public String getXmlContent(){
return m_sXmlContent;
}
public void setServiceGroup(final DBServiceGroup serviceGroup) {
this.serviceGroup = serviceGroup;
}
public void setXmlContent(String sXmlContent){
m_sXmlContent = sXmlContent;
}
public void setXmlContent(String xmlContent) {
this.xmlContent = xmlContent;
}
}
/*
* Copyright 2017 European Commission | CEF eDelivery
*
* Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence");
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* or file: LICENCE-EUPL-v1.1.pdf
*
* Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and limitations under the Licence.
*/
/*
* Copyright 2017 European Commission | CEF eDelivery
*
......@@ -31,96 +16,72 @@ package eu.europa.ec.edelivery.smp.data.model;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.oasis_open.docs.bdxr.ns.smp._2016._05.DocumentIdentifier;
import org.oasis_open.docs.bdxr.ns.smp._2016._05.ParticipantIdentifierType;
import javax.annotation.Nonnull;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.Transient;
import java.io.Serializable;
/**
* ServiceMetadataId generated by hbm2java
*
* @author PEPPOL.AT, BRZ, Philip Helger
*/
import static eu.europa.ec.edelivery.smp.data.model.CommonColumnsLengths.*;
@Embeddable
@ToString
@EqualsAndHashCode
public class DBServiceMetadataID implements Serializable {
private String m_sParticipantIdentifierScheme;
private String m_sParticipantIdentifier;
private String m_sDocumentTypeIdentifierScheme;
private String m_sDocumentTypeIdentifier;
@Deprecated
public DBServiceMetadataID () {}
public DBServiceMetadataID (@Nonnull final ParticipantIdentifierType aBusinessID,
@Nonnull final DocumentIdentifier aDocumentTypeID) {
setBusinessIdentifier (aBusinessID);
setDocumentTypeIdentifier (aDocumentTypeID);
}
@Column (name = "businessIdentifierScheme", nullable = false, length = CommonColumnsLengths.MAX_IDENTIFIER_SCHEME_LENGTH)
public String getBusinessIdentifierScheme () {
return m_sParticipantIdentifierScheme;
}
public void setBusinessIdentifierScheme (final String sBusinessIdentifierScheme) {
m_sParticipantIdentifierScheme = sBusinessIdentifierScheme;
}
@Column (name = "businessIdentifier", nullable = false, length = CommonColumnsLengths.MAX_PARTICIPANT_IDENTIFIER_VALUE_LENGTH)
public String getBusinessIdentifier () {
return m_sParticipantIdentifier;
}
public void setBusinessIdentifier (final String sBusinessIdentifier) {
m_sParticipantIdentifier = sBusinessIdentifier;
}
@Transient
public void setBusinessIdentifier (@Nonnull final ParticipantIdentifierType aPI) {
setBusinessIdentifierScheme (aPI.getScheme ());
setBusinessIdentifier (aPI.getValue ());
}
@Column (name = "documentIdentifierScheme", nullable = false, length = CommonColumnsLengths.MAX_IDENTIFIER_SCHEME_LENGTH)
public String getDocumentTypeIdentifierScheme () {
return m_sDocumentTypeIdentifierScheme;
}
public void setDocumentTypeIdentifierScheme (final String sDocumentIdentifierScheme) {
m_sDocumentTypeIdentifierScheme = sDocumentIdentifierScheme;
}
@Column (name = "documentIdentifier", nullable = false, length = CommonColumnsLengths.MAX_DOCUMENT_TYPE_IDENTIFIER_VALUE_LENGTH)
public String getDocumentTypeIdentifier () {
return m_sDocumentTypeIdentifier;
}
public void setDocumentTypeIdentifier (final String sDocumentIdentifier) {
m_sDocumentTypeIdentifier = sDocumentIdentifier;
}
@Transient
public void setDocumentTypeIdentifier (@Nonnull final DocumentIdentifier aDocTypeID) {
setDocumentTypeIdentifierScheme (aDocTypeID.getScheme ());
setDocumentTypeIdentifier (aDocTypeID.getValue ());
}
@Nonnull
@Transient
public ParticipantIdentifierType asBusinessIdentifier () {
return new ParticipantIdentifierType(m_sParticipantIdentifier, m_sParticipantIdentifierScheme);
}
@Nonnull
@Transient
public DocumentIdentifier asDocumentTypeIdentifier () {
return new DocumentIdentifier(m_sDocumentTypeIdentifier, m_sDocumentTypeIdentifierScheme);
}
private String participantIdScheme;
private String participantIdValue;
private String documentIdScheme;
private String documentIdValue;
@Deprecated
public DBServiceMetadataID() {
}
public DBServiceMetadataID(String participantIdScheme,
String participantIdValue,
String documentIdScheme,
String documentIdValue) {
setBusinessIdentifierScheme(participantIdScheme);
setBusinessIdentifier(participantIdValue);
setDocumentIdentifierScheme(documentIdScheme);
setDocumentIdentifier(documentIdValue);
}
@Column(name = "businessIdentifierScheme", nullable = false, length = MAX_IDENTIFIER_SCHEME_LENGTH)
public String getBusinessIdentifierScheme() {
return participantIdScheme;
}
@Column(name = "businessIdentifier", nullable = false, length = MAX_PARTICIPANT_IDENTIFIER_VALUE_LENGTH)
public String getBusinessIdentifier() {
return participantIdValue;
}
@Column(name = "documentIdentifierScheme", nullable = false, length = MAX_IDENTIFIER_SCHEME_LENGTH)
public String getDocumentIdentifierScheme() {
return documentIdScheme;
}
@Column(name = "documentIdentifier", nullable = false, length = MAX_DOCUMENT_TYPE_IDENTIFIER_VALUE_LENGTH)
public String getDocumentIdentifier() {
return documentIdValue;
}
public void setBusinessIdentifierScheme(String participantIdScheme) {
this.participantIdScheme = participantIdScheme;
}
public void setDocumentIdentifierScheme(String documentIdScheme) {
this.documentIdScheme = documentIdScheme;
}
public void setBusinessIdentifier(String participantIdValue) {
this.participantIdValue = participantIdValue;
}
public void setDocumentIdentifier(String documentIdValue) {
this.documentIdValue = documentIdValue;
}
}
/*
* Copyright 2017 European Commission | CEF eDelivery
*
* Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence");
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* or file: LICENCE-EUPL-v1.1.pdf
*
* Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and limitations under the Licence.
*/
/*
* Copyright 2017 European Commission | CEF eDelivery
*
......@@ -34,55 +19,55 @@ import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
/**
* Represents a single user within the SMP database.
*
* @author PEPPOL.AT, BRZ, Philip Helger
*/
import static eu.europa.ec.edelivery.smp.data.model.CommonColumnsLengths.MAX_USERNAME_LENGTH;
@Entity
@Table (name = "smp_user")
@Table(name = "smp_user")
public class DBUser implements Serializable {
private String m_sUserName;
private String m_sPassword;
private boolean m_bIsAdmin;
private Set <DBOwnership> m_aOwnerships = new HashSet <DBOwnership> ();
public DBUser () {}
private String username;
private String password;
private boolean isAdmin;
private Set<DBOwnership> ownerships = new HashSet<>();
public DBUser() {
}
@Id
@Column(name = "username", unique = true, nullable = false, length = MAX_USERNAME_LENGTH)
public String getUsername() {
return username;
}
@Id
@Column (name = "username", unique = true, nullable = false, length = 256)
public String getUsername () {
return m_sUserName;
}
@Column(name = "password", length = MAX_USERNAME_LENGTH)
public String getPassword() {
return password;
}
public void setUsername (final String sUserName) {
m_sUserName = sUserName;
}
@Column (name = "password",length = 256)
public String getPassword () {
return m_sPassword;
}
@Column(name = "isadmin", nullable = false)
public boolean isAdmin() {
return isAdmin;
}
public void setPassword (final String sPassword) {
m_sPassword = sPassword;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
public Set<DBOwnership> getOwnerships() {
return ownerships;
}
@Column(name = "isadmin", nullable = false)
public boolean isAdmin() {
return m_bIsAdmin;
}
public void setUsername(String username) {
this.username = username;
}
public void setAdmin(boolean isAdmin) {
m_bIsAdmin = isAdmin;
}
public void setPassword(String password) {
this.password = password;
}
@OneToMany (fetch = FetchType.LAZY, mappedBy = "user")
public Set <DBOwnership> getOwnerships () {
return m_aOwnerships;
}
public void setAdmin(boolean isAdmin) {
this.isAdmin = isAdmin;
}
public void setOwnerships (final Set <DBOwnership> aOwnerships) {
m_aOwnerships = aOwnerships;
}
public void setOwnerships(Set<DBOwnership> ownerships) {
this.ownerships = ownerships;
}
}
......@@ -13,21 +13,6 @@
* See the Licence for the specific language governing permissions and limitations under the Licence.
*/
/*
* Copyright 2017 European Commission | CEF eDelivery
*
* Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence");
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* or file: LICENCE-EUPL-v1.1.pdf
*
* Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and limitations under the Licence.
*/
package eu.europa.ec.edelivery.smp.exceptions;
......
......@@ -13,21 +13,6 @@
* See the Licence for the specific language governing permissions and limitations under the Licence.
*/
/*
* Copyright 2017 European Commission | CEF eDelivery
*
* Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence");
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* or file: LICENCE-EUPL-v1.1.pdf
*
* Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and limitations under the Licence.
*/
package eu.europa.ec.edelivery.smp.exceptions;
/**
......
......@@ -13,20 +13,6 @@
* See the Licence for the specific language governing permissions and limitations under the Licence.
*/
/*
* Copyright 2017 European Commission | CEF eDelivery
*
* Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence");
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* or file: LICENCE-EUPL-v1.1.pdf
*
* Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and limitations under the Licence.
*/
package eu.europa.ec.edelivery.smp.exceptions;
/**
......
......@@ -13,21 +13,6 @@
* See the Licence for the specific language governing permissions and limitations under the Licence.
*/
/*
* Copyright 2017 European Commission | CEF eDelivery
*
* Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence");
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* or file: LICENCE-EUPL-v1.1.pdf
*
* Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and limitations under the Licence.
*/
package eu.europa.ec.edelivery.smp.exceptions;
/**
......
......@@ -17,13 +17,13 @@ package eu.europa.ec.edelivery.smp.services;
import eu.europa.ec.cipa.smp.server.conversion.CaseSensitivityNormalizer;
import eu.europa.ec.cipa.smp.server.conversion.ServiceGroupConverter;
import eu.europa.ec.edelivery.smp.exceptions.NotFoundException;
import eu.europa.ec.edelivery.smp.exceptions.UnknownUserException;
import eu.europa.ec.cipa.smp.server.hook.IRegistrationHook;
import eu.europa.ec.edelivery.smp.data.dao.OwnershipDao;
import eu.europa.ec.edelivery.smp.data.dao.ServiceGroupDao;
import eu.europa.ec.edelivery.smp.data.dao.UserDao;
import eu.europa.ec.edelivery.smp.data.model.*;
import eu.europa.ec.edelivery.smp.exceptions.NotFoundException;
import eu.europa.ec.edelivery.smp.exceptions.UnknownUserException;
import org.oasis_open.docs.bdxr.ns.smp._2016._05.ParticipantIdentifierType;
import org.oasis_open.docs.bdxr.ns.smp._2016._05.ServiceGroup;
import org.slf4j.Logger;
......@@ -60,7 +60,7 @@ public class ServiceGroupService {
public ServiceGroup getServiceGroup(ParticipantIdentifierType serviceGroupId) {
ParticipantIdentifierType normalizedServiceGroupId = caseSensitivityNormalizer.normalize(serviceGroupId);
DBServiceGroup dbServiceGroup = serviceGroupDao.find(normalizedServiceGroupId);
DBServiceGroup dbServiceGroup = serviceGroupDao.find(normalizedServiceGroupId.getScheme(), normalizedServiceGroupId.getValue());
if (dbServiceGroup == null) {
throw new NotFoundException("ServiceGroup not found: '%s'", asString(serviceGroupId));
}
......@@ -77,26 +77,26 @@ public class ServiceGroupService {
throw new UnknownUserException(newOwnerName);
}
DBServiceGroup aDBServiceGroup = serviceGroupDao.find(normalizedParticipantId);
DBServiceGroup dbServiceGroup = serviceGroupDao.find(normalizedParticipantId.getScheme(), normalizedParticipantId.getValue());
String extensions = ServiceGroupConverter.extractExtensionsPayload(normalizedServiceGroup);
if (aDBServiceGroup != null) {
aDBServiceGroup.setExtension(extensions);
serviceGroupDao.update(aDBServiceGroup);
if (dbServiceGroup != null) {
dbServiceGroup.setExtension(extensions);
serviceGroupDao.save(dbServiceGroup);
return false;
} else {
// Register in SML (DNS)
m_aHook.create(normalizedParticipantId);
aDBServiceGroup = new DBServiceGroup(new DBServiceGroupID(normalizedParticipantId));
aDBServiceGroup.setExtension(extensions);
serviceGroupDao.save(aDBServiceGroup);
//Save ServiceGroup
dbServiceGroup = new DBServiceGroup(new DBServiceGroupID(normalizedParticipantId.getScheme(), normalizedParticipantId.getValue()));
dbServiceGroup.setExtension(extensions);
serviceGroupDao.save(dbServiceGroup);
// Save the ownership information
final DBOwnershipID ownershipID = new DBOwnershipID(newOwnerName, normalizedParticipantId);
final DBOwnership ownership = new DBOwnership(ownershipID, newOwner, aDBServiceGroup);
//TODO trye to save ownership in one dbUpdate request
final DBOwnershipID ownershipID = new DBOwnershipID(newOwnerName, normalizedParticipantId.getScheme(), normalizedParticipantId.getValue());
final DBOwnership ownership = new DBOwnership(ownershipID, newOwner, dbServiceGroup);
ownershipDao.save(ownership);
return true;
}
......@@ -115,7 +115,7 @@ public class ServiceGroupService {
public void deleteServiceGroup(ParticipantIdentifierType serviceGroupId) {
final ParticipantIdentifierType normalizedServiceGroupId = caseSensitivityNormalizer.normalize(serviceGroupId);
DBServiceGroup dbServiceGroup = serviceGroupDao.find(normalizedServiceGroupId);
DBServiceGroup dbServiceGroup = serviceGroupDao.find(normalizedServiceGroupId.getScheme(), normalizedServiceGroupId.getValue());
if (dbServiceGroup == null) {
throw new NotFoundException("ServiceGroup not found: '%s'", asString(serviceGroupId));
}
......
......@@ -17,14 +17,16 @@ package eu.europa.ec.edelivery.smp.services;
import eu.europa.ec.cipa.smp.server.conversion.CaseSensitivityNormalizer;
import eu.europa.ec.cipa.smp.server.conversion.ServiceMetadataConverter;
import eu.europa.ec.edelivery.smp.exceptions.NotFoundException;
import eu.europa.ec.cipa.smp.server.util.SignatureFilter;
import eu.europa.ec.edelivery.smp.data.dao.ServiceGroupDao;
import eu.europa.ec.edelivery.smp.data.dao.ServiceMetadataDao;
import eu.europa.ec.edelivery.smp.data.model.DBServiceGroup;
import eu.europa.ec.edelivery.smp.data.model.DBServiceMetadata;
import eu.europa.ec.edelivery.smp.data.model.DBServiceMetadataID;
import eu.europa.ec.edelivery.smp.exceptions.NotFoundException;
import org.oasis_open.docs.bdxr.ns.smp._2016._05.DocumentIdentifier;
import org.oasis_open.docs.bdxr.ns.smp._2016._05.ParticipantIdentifierType;
import org.oasis_open.docs.bdxr.ns.smp._2016._05.ServiceGroup;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -35,7 +37,7 @@ import org.w3c.dom.Document;
import java.util.ArrayList;
import java.util.List;
import static eu.europa.ec.smp.api.Identifiers.*;
import static eu.europa.ec.smp.api.Identifiers.asString;
/**
* Created by gutowpa on 14/11/2017.
......@@ -43,8 +45,6 @@ import static eu.europa.ec.smp.api.Identifiers.*;
@Service
public class ServiceMetadataService {
private static final Logger log = LoggerFactory.getLogger(ServiceMetadataService.class);
@Autowired
private CaseSensitivityNormalizer caseSensitivityNormalizer;
......@@ -58,10 +58,14 @@ public class ServiceMetadataService {
private SignatureFilter signatureFilter;
public Document getServiceMetadataDocument(ParticipantIdentifierType serviceGroupId, DocumentIdentifier documentId) {
serviceGroupId = caseSensitivityNormalizer.normalize(serviceGroupId);
documentId = caseSensitivityNormalizer.normalize(documentId);
ParticipantIdentifierType normalizedServiceGroupId = caseSensitivityNormalizer.normalize(serviceGroupId);
DocumentIdentifier normalizedDocId = caseSensitivityNormalizer.normalize(documentId);
DBServiceMetadata serviceMetadata = serviceMetadataDao.find(serviceGroupId, documentId);
DBServiceMetadata serviceMetadata = serviceMetadataDao.find(
normalizedServiceGroupId.getScheme(),
normalizedServiceGroupId.getValue(),
normalizedDocId.getScheme(),
normalizedDocId.getValue());
if (serviceMetadata == null || serviceMetadata.getXmlContent() == null) {
throw new NotFoundException("ServiceMetadata not found, ServiceGroupID: '%s', DocumentID: '%s'", asString(serviceGroupId), asString(documentId));
......@@ -74,6 +78,7 @@ public class ServiceMetadataService {
/**
* Creates or updates ServiceMetadata
*
* @return True if new ServiceMetadata was created. False if existing one was updated.
*/
@Transactional
......@@ -81,14 +86,24 @@ public class ServiceMetadataService {
ParticipantIdentifierType normalizedServiceGroupId = caseSensitivityNormalizer.normalize(serviceGroupId);
DocumentIdentifier normalizedDocId = caseSensitivityNormalizer.normalize(documentId);
if (serviceGroupDao.find(normalizedServiceGroupId) == null) {
DBServiceGroup serviceGroup = serviceGroupDao.find(normalizedServiceGroupId.getScheme(), normalizedServiceGroupId.getValue());
if (serviceGroup == null) {
throw new NotFoundException("ServiceGroup not found: '%s'", asString(serviceGroupId));
}
boolean alreadyExisted = serviceMetadataDao.remove(normalizedServiceGroupId, normalizedDocId);
boolean alreadyExisted = serviceMetadataDao.remove(
normalizedServiceGroupId.getScheme(),
normalizedServiceGroupId.getValue(),
normalizedDocId.getScheme(),
normalizedDocId.getValue());
DBServiceMetadata serviceMetadata = new DBServiceMetadata();
serviceMetadata.setId(new DBServiceMetadataID(normalizedServiceGroupId, normalizedDocId));
serviceMetadata.setId(new DBServiceMetadataID(
normalizedServiceGroupId.getScheme(),
normalizedServiceGroupId.getValue(),
normalizedDocId.getScheme(),
normalizedDocId.getValue()));
serviceMetadata.setXmlContent(xmlContent);
serviceMetadataDao.save(serviceMetadata);
return !alreadyExisted;
......@@ -99,18 +114,26 @@ public class ServiceMetadataService {
ParticipantIdentifierType normalizedServiceGroupId = caseSensitivityNormalizer.normalize(serviceGroupId);
DocumentIdentifier normalizedDocId = caseSensitivityNormalizer.normalize(documentId);
boolean serviceMetadataRemoved = serviceMetadataDao.remove(normalizedServiceGroupId, normalizedDocId);
boolean serviceMetadataRemoved = serviceMetadataDao.remove(
normalizedServiceGroupId.getScheme(),
normalizedServiceGroupId.getValue(),
normalizedDocId.getScheme(),
normalizedDocId.getValue());
if (!serviceMetadataRemoved) {
throw new NotFoundException("ServiceGroup not found: '%s'", asString(serviceGroupId));
}
}
public List<DocumentIdentifier> findServiceMetadataIdentifiers(ParticipantIdentifierType participantId) {
List<DBServiceMetadataID> metadataIds = serviceMetadataDao.findIdsByServiceGroup(participantId);
ParticipantIdentifierType normalizedServiceGroupId = caseSensitivityNormalizer.normalize(participantId);
List<DBServiceMetadataID> metadataIds = serviceMetadataDao.findIdsByServiceGroup(
normalizedServiceGroupId.getScheme(),
normalizedServiceGroupId.getValue());
List<DocumentIdentifier> documentIds = new ArrayList();
for (DBServiceMetadataID metadataId : metadataIds) {
DocumentIdentifier documentIdentifier = new DocumentIdentifier(metadataId.getDocumentTypeIdentifier(), metadataId.getDocumentTypeIdentifierScheme());
DocumentIdentifier documentIdentifier = new DocumentIdentifier(metadataId.getDocumentIdentifier(), metadataId.getDocumentIdentifierScheme());
documentIds.add(documentIdentifier);
}
return documentIds;
......
......@@ -137,4 +137,30 @@ public class ServiceMetadataIntegrationTest {
String newDescription = resultServiceMetadataDoc.getElementsByTagName("ServiceDescription").item(0).getTextContent();
assertEquals("New Description", newDescription);
}
@Test
public void findServiceMetadataIdsPositiveScenario() throws IOException, JAXBException, TransformerException {
//given
String serviceMetadataXml1 = loadDocumentAsString(SERVICE_METADATA_XML_PATH);
serviceMetadataService.saveServiceMetadata(SERVICE_GROUP_ID, DOC_ID, serviceMetadataXml1);
String secondDocIdValue = "second-doc-id";
DocumentIdentifier secondDocId = new DocumentIdentifier(secondDocIdValue, DOC_ID.getScheme());
ServiceMetadata serviceMetadata2 = unmarshal(loadDocumentAsString(SERVICE_METADATA_XML_PATH));
serviceMetadata2.getServiceInformation().getDocumentIdentifier().setValue(secondDocIdValue);
String serviceMetadataXml2 = marshall(serviceMetadata2);
serviceMetadataService.saveServiceMetadata(SERVICE_GROUP_ID, secondDocId, serviceMetadataXml2);
//when
List<DocumentIdentifier> docIds = serviceMetadataService.findServiceMetadataIdentifiers(SERVICE_GROUP_ID);
//then
assertEquals(2, docIds.size());
DocumentIdentifier docId1 = docIds.get(0);
assertEquals(DOC_ID.getScheme(), docId1.getScheme());
assertEquals(DOC_ID.getValue(), docId1.getValue());
DocumentIdentifier docId2 = docIds.get(1);
assertEquals(DOC_ID.getScheme(), docId2.getScheme());
assertEquals(secondDocIdValue, docId2.getValue());
}
}
......@@ -36,16 +36,6 @@
</properties>
<dependencies>
<!--TODO remove me -->
<dependency>
<groupId>com.helger</groupId>
<artifactId>ph-commons</artifactId>
<version>5.6.0</version>
</dependency>
<dependency>
<groupId>eu.europa.ec.cipa</groupId>
<artifactId>smp-server-library</artifactId>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment