diff --git a/pom.xml b/pom.xml index 495002fe80f236908a2da10995c86d16d6306022..77f675b0820fa02d62467219ccba3e58625f1704 100644 --- a/pom.xml +++ b/pom.xml @@ -32,8 +32,7 @@ <properties> <sonar.host.url>http://edelquality.westeurope.cloudapp.azure.com:9000/sonar/</sonar.host.url> - <!-- This class crashes sonar analysis. There is already a JIRA ticket for rewriting it. --> - <sonar.exclusions>**/DBMSDataManager.java</sonar.exclusions> + <sonar.exclusions>**/smp/data/model/*, **/smp/exceptions/*</sonar.exclusions> </properties> <build> diff --git a/smp-api/src/main/java/eu/europa/ec/smp/api/validators/BdxSmpOasisValidator.java b/smp-api/src/main/java/eu/europa/ec/smp/api/validators/BdxSmpOasisValidator.java index 4cbc7cefae54c042ae253a6875ea7ae1dfba1e8a..87ff33128de286446c0bc3d1ab99f5a088daa124 100644 --- a/smp-api/src/main/java/eu/europa/ec/smp/api/validators/BdxSmpOasisValidator.java +++ b/smp-api/src/main/java/eu/europa/ec/smp/api/validators/BdxSmpOasisValidator.java @@ -43,7 +43,7 @@ public class BdxSmpOasisValidator { validator.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, ""); validator.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, ""); } catch (SAXException e) { - throw new RuntimeException("Unable to initialize BDX SMP OASIS XSD schema validator.", e); + throw new IllegalStateException("Unable to initialize BDX SMP OASIS XSD schema validator.", e); } } diff --git a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/conversion/ServiceGroupConverter.java b/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/conversion/ServiceGroupConverter.java index 8ff7cf7fd9387b54bbeff69443233bc122faddf5..b67ca7fa65ea8415a10b7b55d8cb98897335e9e4 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/conversion/ServiceGroupConverter.java +++ b/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/conversion/ServiceGroupConverter.java @@ -15,8 +15,15 @@ package eu.europa.ec.cipa.smp.server.conversion; -import eu.europa.ec.cipa.smp.server.errors.exceptions.XmlParsingException; +import eu.europa.ec.edelivery.smp.data.model.DBServiceGroupId; +import eu.europa.ec.edelivery.smp.exceptions.ConversionException; +import eu.europa.ec.edelivery.smp.exceptions.XmlParsingException; +import eu.europa.ec.cipa.smp.server.util.ExtensionUtils; +import eu.europa.ec.edelivery.smp.data.model.DBServiceGroup; +import org.oasis_open.docs.bdxr.ns.smp._2016._05.ExtensionType; +import org.oasis_open.docs.bdxr.ns.smp._2016._05.ParticipantIdentifierType; import org.oasis_open.docs.bdxr.ns.smp._2016._05.ServiceGroup; +import org.oasis_open.docs.bdxr.ns.smp._2016._05.ServiceMetadataReferenceCollectionType; import org.w3c.dom.Document; import org.xml.sax.SAXException; @@ -26,9 +33,13 @@ import javax.xml.bind.Unmarshaller; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; +import javax.xml.stream.XMLStreamException; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + import static java.nio.charset.StandardCharsets.UTF_8; /** @@ -61,6 +72,20 @@ public class ServiceGroupConverter { } } + public static ServiceGroup toServiceGroup(DBServiceGroup dbServiceGroup){ + ServiceGroup serviceGroup = new ServiceGroup(); + ParticipantIdentifierType identifier = new ParticipantIdentifierType(dbServiceGroup.getId().getBusinessIdentifier(), dbServiceGroup.getId().getBusinessIdentifierScheme()); + serviceGroup.setParticipantIdentifier(identifier); + try { + List<ExtensionType> extensions = ExtensionUtils.unmarshalExtensions(dbServiceGroup.getExtension()); + serviceGroup.getExtensions().addAll(extensions); + } catch (JAXBException e) { + throw new ConversionException(e); + } + serviceGroup.setServiceMetadataReferenceCollection(new ServiceMetadataReferenceCollectionType(new ArrayList())); + return serviceGroup; + } + private static Document parse(String serviceGroupXml) throws ParserConfigurationException, IOException, SAXException { InputStream inputStream = new ByteArrayInputStream(serviceGroupXml.getBytes(UTF_8)); return getDocumentBuilder().parse(inputStream); @@ -72,4 +97,16 @@ public class ServiceGroupConverter { documentBuilderFactory.setFeature(PARSER_DISALLOW_DTD_PARSING_FEATURE, true); return documentBuilderFactory.newDocumentBuilder(); } + + public static String extractExtensionsPayload(ServiceGroup serviceGroup) { + try { + return ExtensionUtils.marshalExtensions(serviceGroup.getExtensions()); + } catch (JAXBException | XMLStreamException e) { + throw new ConversionException(e); + } + } + + public static DBServiceGroupId toDbModel(ParticipantIdentifierType serviceGroupId){ + return new DBServiceGroupId(serviceGroupId.getScheme(), serviceGroupId.getValue()); + } } diff --git a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/conversion/ServiceMetadataConverter.java b/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/conversion/ServiceMetadataConverter.java index 34f42450ff299ce5a4ec96e6931d3978a0231d8f..16bce44a3dc63680e9fb688c25388d331fceda6d 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/conversion/ServiceMetadataConverter.java +++ b/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/conversion/ServiceMetadataConverter.java @@ -15,7 +15,10 @@ package eu.europa.ec.cipa.smp.server.conversion; -import eu.europa.ec.cipa.smp.server.errors.exceptions.XmlParsingException; +import eu.europa.ec.edelivery.smp.data.model.DBServiceMetadataId; +import eu.europa.ec.edelivery.smp.exceptions.XmlParsingException; +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.ServiceMetadata; import org.w3c.dom.Document; import org.w3c.dom.Node; @@ -100,4 +103,10 @@ public class ServiceMetadataConverter { return dbf.newDocumentBuilder(); } + public static DBServiceMetadataId toDbModel(ParticipantIdentifierType participantId, DocumentIdentifier docId){ + return new DBServiceMetadataId(participantId.getScheme(), + participantId.getValue(), + docId.getScheme(), + docId.getValue()); + } } diff --git a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/data/dbms/DBMSDataManager.java b/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/data/dbms/DBMSDataManager.java deleted file mode 100644 index 90bfe8091f6ccda5c9ce489894a2aa623fad6920..0000000000000000000000000000000000000000 --- a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/data/dbms/DBMSDataManager.java +++ /dev/null @@ -1,665 +0,0 @@ -/* - * 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.cipa.smp.server.data.dbms; - -import eu.europa.ec.cipa.smp.server.conversion.CaseSensitivityNormalizer; -import eu.europa.ec.cipa.smp.server.conversion.ServiceMetadataConverter; -import eu.europa.ec.cipa.smp.server.data.dbms.model.*; -import eu.europa.ec.cipa.smp.server.errors.exceptions.NotFoundException; -import eu.europa.ec.cipa.smp.server.errors.exceptions.UnknownUserException; -import eu.europa.ec.cipa.smp.server.hook.IRegistrationHook; -import eu.europa.ec.cipa.smp.server.util.ExtensionUtils; -import eu.europa.ec.cipa.smp.server.util.IdentifierUtils; -import eu.europa.ec.cipa.smp.server.util.to_be_removed.EChange; -import org.oasis_open.docs.bdxr.ns.smp._2016._05.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.xml.bind.JAXBException; -import javax.xml.stream.XMLStreamException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -/** - * A Hibernate implementation of the DataManager interface. - * - * @author PEPPOL.AT, BRZ, Philip Helger - */ -@Service -@Transactional -public /*final*/ class DBMSDataManager /*extends JPAEnabledManager*/ /*implements IDataManager*/ { - private static final Logger s_aLogger = LoggerFactory.getLogger(DBMSDataManager.class); - - //@Autowired - //EntityManager em; - - @Autowired - private IRegistrationHook m_aHook; - - @Autowired - private CaseSensitivityNormalizer caseSensitivityNormalizer; - - @PersistenceContext - EntityManager entityManager; - - private final ObjectFactory m_aObjFactory = new ObjectFactory(); - - public DBMSDataManager() { - /* - super(new IEntityManagerProvider() { - // This additional indirection level is required!!! - // So that for every request the correct getInstance is invoked! - @Nonnull - public EntityManager getEntityManager() { - //return SMPEntityManagerWrapper.getInstance().getEntityManager(); - EntityManagerFactory emf = ContextLoader.getCurrentWebApplicationContext().getBean(EntityManagerFactory.class); - return EntityManagerFactoryUtils.getTransactionalEntityManager(emf); - } - }); - */ - } - - /* - public DBMSDataManager() { - this(RegistrationHookFactory.createInstance(), new CaseSensitivityNormalizer()); - } - - public DBMSDataManager(@Nonnull final IRegistrationHook aHook, CaseSensitivityNormalizer caseSensitivityNormalizer) { - super(new IEntityManagerProvider() { - // This additional indirection level is required!!! - // So that for every request the correct getInstance is invoked! - @Nonnull - public EntityManager getEntityManager() { - return SMPEntityManagerWrapper.getInstance().getEntityManager(); - } - }); - - ValueEnforcer.notNull(aHook, "Hook"); - - // Exceptions are handled by logging them - setCustomExceptionHandler(new LoggingExceptionHandler()); - - // To avoid some EclipseLink logging issues - setUseTransactionsForSelect(true); - - m_aHook = aHook; - this.caseSensitivityNormalizer = caseSensitivityNormalizer; - } - */ - - public void setCaseSensitivityNormalizer(CaseSensitivityNormalizer caseSensitivityNormalizer) { - this.caseSensitivityNormalizer = caseSensitivityNormalizer; - } - - /** - * Check if an SMP user matching the user name of the BasicAuth credentials - * exists, and that the passwords match. So this method verifies that the - * BasicAuth credentials are valid. - * - * @param sUsername The credentials to be validated. May not be <code>null</code>. - * @return The matching non-<code>null</code> {@link DBUser}. - * @throws UnknownUserException If no user matching the passed user name is present - * @throws UnauthorizedException If the password in the credentials does not match the stored - * password - */ - @Nonnull - ////@Override - public DBUser _verifyUser(@Nonnull final String sUsername) throws UnknownUserException{ - - //final String sUsername = aCredentials.getUserName(); - - final DBUser aDBUser = entityManager.find(DBUser.class, sUsername); - - // Check that the user exists - if (aDBUser == null) { - throw new UnknownUserException(sUsername); - } -/* - // Check that the password is correct - if (!isNullPasswordAllowed(aDBUser.getPassword(),aCredentials.getPassword())){ - if(aCredentials.getPassword()== null || isBlank(aDBUser.getPassword()) || - ! BCrypt.checkpw(aCredentials.getPassword(), aDBUser.getPassword())) { - throw new UnauthorizedException("Illegal password for user '" + sUsername + "'"); - } - } - - if (s_aLogger.isDebugEnabled()) { - s_aLogger.debug("Verified credentials of user '" + sUsername + "' successfully"); - } -*/ - return aDBUser; - } -/* - - private boolean isNullPasswordAllowed(String requestPassword, String databasePassword){ - return (isBlank(requestPassword) && isBlank(databasePassword)); - } -*/ - - /** - * Verify that the passed service group is owned by the user specified in the - * credentials. - * - * @param aServiceGroupID The service group to be verified - * @param username The credentials to be checked - * @throws UnauthorizedException If the participant identifier is not owned by the user specified in - * the credentials - */ - @Nonnull - private void _verifyOwnership(@Nonnull final ParticipantIdentifierType aServiceGroupID, - @Nonnull final String username) { -/* - if (_isAdmin(username)){ - return; - } - - final DBOwnershipID aOwnershipID = new DBOwnershipID(username, aServiceGroupID); - final DBOwnership aOwnership = getEntityManager().find(DBOwnership.class, aOwnershipID); - if (aOwnership == null) { - throw new UnauthorizedException("User '" + - username + - "' does not own " + - IdentifierUtils.getIdentifierURIEncoded(aServiceGroupID)); - } - - if (s_aLogger.isDebugEnabled()) - s_aLogger.debug("Verified service group ID " + - IdentifierUtils.getIdentifierURIEncoded(aServiceGroupID) + - " is owned by user '" + - username + - "'"); - */ - } - - private boolean _isAdmin(@Nonnull String username) { - final DBUser aDBUser = entityManager.find(DBUser.class, username); - return aDBUser.isAdmin(); - } - - /** - * Checks if exists a ServiceGroup with that ServiceGroupId - * @param aServiceGroupID Service Group Id - * @throws NotFoundException NotFoundException is thrown if Service Group does not exist - */ - private void _verifyServiceGroup(ParticipantIdentifierType aServiceGroupID) throws NotFoundException { - final DBServiceGroupID aDBServiceGroupID = new DBServiceGroupID(aServiceGroupID); - DBServiceGroup aDBServiceGroup = entityManager.find(DBServiceGroup.class, aDBServiceGroupID); - if(aDBServiceGroup == null) { - throw new NotFoundException(String.format("ServiceGroup '%s::%s' was not found", aServiceGroupID.getScheme(), aServiceGroupID.getValue())); - } - } - - - @Nonnull - public Collection<ParticipantIdentifierType> getServiceGroupList(@Nonnull final String username) throws Throwable { - /* - JPAExecutionResult<Collection<ParticipantIdentifierType>> ret; - ret = doSelect(new Callable<Collection<ParticipantIdentifierType>>() { - @Nonnull - @ReturnsMutableCopy - public Collection<ParticipantIdentifierType> call() throws Exception { - */ - final DBUser aDBUser = _verifyUser(username); - - final List<DBOwnership> aDBOwnerships = entityManager.createQuery("SELECT p FROM DBOwnership p WHERE p.user = :user", - DBOwnership.class) - .setParameter("user", aDBUser) - .getResultList(); - - final Collection<ParticipantIdentifierType> aList = new ArrayList<ParticipantIdentifierType>(); - for (final DBOwnership aDBOwnership : aDBOwnerships) { - final DBServiceGroupID aDBServiceGroupID = aDBOwnership.getServiceGroup().getId(); - aList.add(aDBServiceGroupID.asBusinessIdentifier()); - } - return aList; - /* - } - }); - return ret.getOrThrow(); - */ - } - - - @Nullable - public ServiceGroup getServiceGroup(@Nonnull final ParticipantIdentifierType aServiceGroupID) { - final ParticipantIdentifierType normalizedServiceGroupID = caseSensitivityNormalizer.normalize(aServiceGroupID); - /* - JPAExecutionResult<ServiceGroup> ret; - ret = doInTransaction(getEntityManager(), true, new Callable<ServiceGroup>() { - @Nullable - public ServiceGroup call() throws Exception { - */ - final DBServiceGroupID aDBServiceGroupID = new DBServiceGroupID(normalizedServiceGroupID); - final DBServiceGroup aDBServiceGroup = entityManager.find(DBServiceGroup.class, aDBServiceGroupID); - if (aDBServiceGroup == null) { - s_aLogger.warn("No such service group to retrieve: " + - IdentifierUtils.getIdentifierURIEncoded(normalizedServiceGroupID)); - return null; - } - - // Convert service group DB to service group service - final ServiceGroup aServiceGroup = m_aObjFactory.createServiceGroup(); - aServiceGroup.setParticipantIdentifier(normalizedServiceGroupID); - List<ExtensionType> extensions = null; - try { - extensions = ExtensionUtils.unmarshalExtensions(aDBServiceGroup.getExtension()); - } catch (JAXBException e) { - throw new RuntimeException(e); - } - aServiceGroup.getExtensions().addAll(extensions); - // This is set by the REST interface: - // ret.setServiceMetadataReferenceCollection(value) - return aServiceGroup; - /* - } - }); - try { - return ret.getOrThrow(); - } catch (Throwable throwable) { - //TODO Don't bother about it, this class will be removed in next sprint. - throw (RuntimeException)throwable; - } - */ - } - - public boolean saveServiceGroup(@Nonnull final ServiceGroup serviceGroup, - @Nonnull final String newOwnerName) { - - final ServiceGroup normalizedServiceGroup = normalizeIdentifierCaseSensitivity(serviceGroup); - /* - JPAExecutionResult<Boolean> ret; - final EntityManager aEM = getEntityManager(); - ret = doInTransaction(aEM, true, new Callable<Boolean>() { - public Boolean call() throws JAXBException, XMLStreamException { - */ - final DBUser aDBUser = _verifyUser(newOwnerName); - final DBServiceGroupID aDBServiceGroupID = new DBServiceGroupID(normalizedServiceGroup.getParticipantIdentifier()); - - // Check if the passed service group ID is already in use - DBServiceGroup aDBServiceGroup = entityManager.find(DBServiceGroup.class, aDBServiceGroupID); - - String extensions = null; - try { - extensions = ExtensionUtils.marshalExtensions(normalizedServiceGroup.getExtensions()); - } catch (JAXBException|XMLStreamException e) { - throw new RuntimeException(e); - } - if (aDBServiceGroup != null) { - // The business did exist. So it must be owned by the passed user. - - //TODO: Probably verification is no longer needed as anly SMP_ADMIN can call this method - //_verifyOwnership(serviceGroup.getParticipantIdentifier(), newOwnerName); - - // Simply update the extension - aDBServiceGroup.setExtension(extensions); - entityManager.merge(aDBServiceGroup); - return false; - } else { - - // It's a new service group - m_aHook.create(normalizedServiceGroup.getParticipantIdentifier()); - - // Did not exist. Create it. - aDBServiceGroup = new DBServiceGroup(aDBServiceGroupID); - aDBServiceGroup.setExtension(extensions); - entityManager.persist(aDBServiceGroup); - - // Save the ownership information - final DBOwnershipID aDBOwnershipID = new DBOwnershipID(newOwnerName, normalizedServiceGroup.getParticipantIdentifier()); - final DBOwnership aDBOwnership = new DBOwnership(aDBOwnershipID, aDBUser, aDBServiceGroup); - entityManager.persist(aDBOwnership); - return true; - } - /* - } - }); - try { - return ret.getOrThrow(); - } catch (Throwable throwable) { - //TODO Don't bother about it, this class will be removed in next sprint. - throw (RuntimeException)throwable; - } - */ - } - - private ServiceGroup normalizeIdentifierCaseSensitivity(ServiceGroup serviceGroup) { - final ServiceGroup sg = new ServiceGroup(); - sg.setParticipantIdentifier(caseSensitivityNormalizer.normalize(serviceGroup.getParticipantIdentifier())); - sg.setServiceMetadataReferenceCollection(serviceGroup.getServiceMetadataReferenceCollection()); - sg.getExtensions().addAll(serviceGroup.getExtensions()); - return sg; - } - -/* - - private ServiceGroup normalizeIdentifierCaseSensitivity(@Nonnull ServiceGroup aServiceGroup) { - final ServiceGroup sg = new ServiceGroup(); - sg.setParticipantIdentifier(caseSensitivityNormalizer.normalize(aServiceGroup.getParticipantIdentifier())); - sg.setServiceMetadataReferenceCollection(aServiceGroup.getServiceMetadataReferenceCollection()); - sg.getExtensions().addAll(aServiceGroup.getExtensions()); - return sg; - } -*/ - - //@Override - public void deleteServiceGroup(@Nonnull final ParticipantIdentifierType aServiceGroupID) { - final ParticipantIdentifierType normalizedServiceGroupId = caseSensitivityNormalizer.normalize(aServiceGroupID); - /* - JPAExecutionResult<EChange> ret; - ret = doInTransaction(getEntityManager(), true, new Callable<EChange>() { - @Nonnull - public EChange call() { - */ - //_verifyUser(username); - - // Check if the service group is existing - //final EntityManager aEM = getEntityManager(); - final DBServiceGroupID aDBServiceGroupID = new DBServiceGroupID(normalizedServiceGroupId); - final DBServiceGroup aDBServiceGroup = entityManager.find(DBServiceGroup.class, aDBServiceGroupID); - if (aDBServiceGroup == null) { - s_aLogger.warn("No such service group to delete: " + - IdentifierUtils.getIdentifierURIEncoded(normalizedServiceGroupId)); - throw new NotFoundException(IdentifierUtils.getIdentifierURIEncoded(aServiceGroupID)); - } - - // Check the ownership afterwards, so that only existing serviceGroups are checked - //_verifyOwnership(normalizedServiceGroupId, username); - - _removeServiceGroup(aDBServiceGroup); - - m_aHook.delete(normalizedServiceGroupId); - - //return EChange.CHANGED; - /* - } - }); - if (ret.hasThrowable()) { - //TODO Don't bother about it, this class will be removed in next sprint. - throw (RuntimeException)ret.getThrowable(); - }else if (ret.get().isUnchanged()) - throw new NotFoundException(IdentifierUtils.getIdentifierURIEncoded(aServiceGroupID)); - */ - } - - private void _removeServiceGroup(DBServiceGroup dbServiceGroup){ - entityManager.createQuery("DELETE FROM DBOwnership o WHERE o.id.businessIdentifierScheme = :scheme and o.id.businessIdentifier = :id") - .setParameter("scheme", dbServiceGroup.getId().getBusinessIdentifierScheme()) - .setParameter("id", dbServiceGroup.getId().getBusinessIdentifier()) - .executeUpdate(); - - entityManager.remove(dbServiceGroup); - } - - @Nonnull - public List<DBServiceMetadataID> getDocumentTypes(@Nonnull final ParticipantIdentifierType aServiceGroupID) throws Throwable { - final ParticipantIdentifierType normalizedServiceGroupId = caseSensitivityNormalizer.normalize(aServiceGroupID); - /* - JPAExecutionResult<List<DBServiceMetadataID>> ret; - ret = doSelect(new Callable<List<DBServiceMetadataID>>() { - @Nonnull - @ReturnsMutableCopy - public List<DBServiceMetadataID> call() throws Exception { - */ - final List<DBServiceMetadata> aServices = entityManager.createQuery("SELECT p FROM DBServiceMetadata p WHERE p.id.businessIdentifierScheme = :scheme AND p.id.businessIdentifier = :value", - DBServiceMetadata.class) - .setParameter("scheme", - normalizedServiceGroupId.getScheme()) - .setParameter("value", - normalizedServiceGroupId.getValue()) - .getResultList(); - - final List<DBServiceMetadataID> aList = new ArrayList<DBServiceMetadataID>(); - for (final DBServiceMetadata aService : aServices) - aList.add(aService.getId()); - return aList; - /* - } - }); - return ret.getOrThrow(); - */ - } - - @Nonnull - public Collection<ServiceMetadata> getServices(@Nonnull final ParticipantIdentifierType aServiceGroupID) throws Throwable { - final ParticipantIdentifierType normalizedServiceGroupId = caseSensitivityNormalizer.normalize(aServiceGroupID); - /* - JPAExecutionResult<Collection<ServiceMetadata>> ret; - ret = doSelect(new Callable<Collection<ServiceMetadata>>() { - @Nonnull - @ReturnsMutableCopy - public Collection<ServiceMetadata> call() throws Exception { - */ - final List<DBServiceMetadata> aServices = entityManager.createQuery("SELECT p FROM DBServiceMetadata p WHERE p.id.businessIdentifierScheme = :scheme AND p.id.businessIdentifier = :value", - DBServiceMetadata.class) - .setParameter("scheme", - normalizedServiceGroupId.getScheme()) - .setParameter("value", - normalizedServiceGroupId.getValue()) - .getResultList(); - - final List<ServiceMetadata> aList = new ArrayList<ServiceMetadata>(); - for (final DBServiceMetadata aService : aServices) { - ServiceMetadata aServiceMetadata = ServiceMetadataConverter.unmarshal(aService.getXmlContent()); - aList.add(aServiceMetadata); - } - return aList; - /* - } - }); - return ret.getOrThrow(); - */ - } - - @Nullable - public String getService(@Nonnull final ParticipantIdentifierType aServiceGroupID, - @Nonnull final DocumentIdentifier aDocTypeID){ - final ParticipantIdentifierType normalizedServiceGroupId = caseSensitivityNormalizer.normalize(aServiceGroupID); - final DocumentIdentifier normalizedDocId = caseSensitivityNormalizer.normalize(aDocTypeID); - /* - JPAExecutionResult<String> ret; - ret = doSelect(new Callable<String>() { - public String call() throws Exception { - */ - final DBServiceMetadataID aDBServiceMetadataID = new DBServiceMetadataID(normalizedServiceGroupId, normalizedDocId); - final DBServiceMetadata aDBServiceMetadata = entityManager.find(DBServiceMetadata.class, - aDBServiceMetadataID); - - if (aDBServiceMetadata == null) { - s_aLogger.info("Service metadata with ID " + - IdentifierUtils.getIdentifierURIEncoded(normalizedServiceGroupId) + - " / " + - IdentifierUtils.getIdentifierURIEncoded(normalizedDocId) + - " not found"); - return null; - } - - return aDBServiceMetadata.getXmlContent(); - /* - } - }); - try { - return ret.getOrThrow(); - } catch (Throwable throwable) { - //TODO Don't bother about it, this class will be removed in next sprint. - throw new RuntimeException(throwable); - } - */ - } - - //@Override - public boolean saveService(@Nonnull final ParticipantIdentifierType aServiceGroupID, - @Nonnull final DocumentIdentifier aDocTypeID, - @Nonnull final String sXmlContent /*, - @Nonnull final String username*/){ - boolean newServiceCreated = true; - - final ParticipantIdentifierType normalizedServiceGroupId = caseSensitivityNormalizer.normalize(aServiceGroupID); - final DocumentIdentifier normalizedDocId = caseSensitivityNormalizer.normalize(aDocTypeID); - - //_verifyUser(username); - _verifyServiceGroup(normalizedServiceGroupId); - //_verifyOwnership(normalizedServiceGroupId, username); - - // Delete an eventually contained previous service in a separate transaction - try { - if (_deleteService(normalizedServiceGroupId, normalizedDocId) == EChange.CHANGED) { - newServiceCreated = false; - } - } catch (Throwable throwable) { - //TODO Don't bother about it, this class will be removed in next sprint. - throw new RuntimeException(throwable); - } - - // Create a new entry - /* - JPAExecutionResult<?> ret = doInTransaction(getEntityManager(), true, new Runnable() { - public void run() { - */ - //final EntityManager aEM = getEntityManager(); - - // Check if an existing service is already contained - // This should have been deleted previously! - final DBServiceMetadataID aDBServiceMetadataID = new DBServiceMetadataID(normalizedServiceGroupId, normalizedDocId); - DBServiceMetadata aDBServiceMetadata = entityManager.find(DBServiceMetadata.class, aDBServiceMetadataID); - if (aDBServiceMetadata != null) { - throw new IllegalStateException("No DB ServiceMeta data with ID " + - IdentifierUtils.getIdentifierURIEncoded(normalizedServiceGroupId) + - " should be present!"); - } - - // Create a new entry - aDBServiceMetadata = new DBServiceMetadata(); - aDBServiceMetadata.setId(aDBServiceMetadataID); - aDBServiceMetadata.setXmlContent(sXmlContent); - /* - try { - _convertFromServiceToDB(normalizedServiceGroupId, normalizedDocId, sXmlContent, aDBServiceMetadata); - } catch (JAXBException | XMLStreamException e) { - throw new IllegalStateException("Problems converting from Service to DB", e); - } - */ - entityManager.persist(aDBServiceMetadata); - /* - } - }); - if (ret.hasThrowable()) { - //TODO Don't bother about it, this class will be removed in next sprint. - throw new RuntimeException(ret.getThrowable()); - } - */ - return newServiceCreated; - } - - @Nonnull - private EChange _deleteService(@Nonnull final ParticipantIdentifierType aServiceGroupID, - @Nonnull final DocumentIdentifier aDocTypeID){ - /* - JPAExecutionResult<EChange> ret; - ret = doInTransaction(getEntityManager(), true, new Callable<EChange>() { - public EChange call() { - */ - //final EntityManager aEM = getEntityManager(); - - final DBServiceMetadataID aDBServiceMetadataID = new DBServiceMetadataID(aServiceGroupID, aDocTypeID); - final DBServiceMetadata aDBServiceMetadata = entityManager.find(DBServiceMetadata.class, aDBServiceMetadataID); - if (aDBServiceMetadata == null) { - // There were no service to delete. - s_aLogger.warn("No such service to delete: " + - IdentifierUtils.getIdentifierURIEncoded(aServiceGroupID) + - " / " + - IdentifierUtils.getIdentifierURIEncoded(aDocTypeID)); - return EChange.UNCHANGED; - } - - // Remove main service data - entityManager.remove(aDBServiceMetadata); - return EChange.CHANGED; - /* - } - }); - try { - return ret.getOrThrow(); - } catch (Throwable throwable) { - //TODO Don't bother about it, this class will be removed in next sprint. - throw new RuntimeException(throwable); - } - */ - } - - //@Override - public void deleteService(@Nonnull final ParticipantIdentifierType aServiceGroupID, - @Nonnull final DocumentIdentifier aDocTypeID /*, - @Nonnull final String username*/){ - - final ParticipantIdentifierType normalizedServiceGroupId = caseSensitivityNormalizer.normalize(aServiceGroupID); - final DocumentIdentifier normalizedDocId = caseSensitivityNormalizer.normalize(aDocTypeID); - - //_verifyUser(username); - _verifyServiceGroup(normalizedServiceGroupId); - //_verifyOwnership(normalizedServiceGroupId, username); - - final EChange eChange = _deleteService(normalizedServiceGroupId, normalizedDocId); - if (EChange.UNCHANGED.equals(eChange)) - throw new NotFoundException(IdentifierUtils.getIdentifierURIEncoded(normalizedServiceGroupId) + - " / " + - IdentifierUtils.getIdentifierURIEncoded(normalizedDocId)); - } - - /* - private static void _convertFromServiceToDB(@Nonnull final ParticipantIdentifierType aServiceGroupID, - @Nonnull final DocumentIdentifier aDocTypeID, - @Nonnull final String sXmlContent, - @Nonnull final DBServiceMetadata aDBServiceMetadata) throws JAXBException, XMLStreamException { - // Update it. - ServiceMetadata aServiceMetadata = ServiceMetadataConverter.unmarshal(sXmlContent); - final ServiceInformationType aServiceInformation = aServiceMetadata.getServiceInformation(); - if(aServiceInformation != null && aServiceInformation.getExtensions().size() > 0) { - aDBServiceMetadata.setExtension(ExtensionUtils.marshalExtensions(aServiceInformation.getExtensions())); - } - final RedirectType aRedirect = aServiceMetadata.getRedirect(); - if(aRedirect != null && aRedirect.getExtensions().size() > 0) { - aDBServiceMetadata.setExtension(ExtensionUtils.marshalExtensions(aRedirect.getExtensions())); - } - aDBServiceMetadata.setXmlContent(sXmlContent); - } - */ - - - //TODO remove me - public EntityManager getCurrentEntityManager() { - //return getEntityManager(); - return entityManager; - } -/* - private EntityManager getEntityManager() { - //return getEntityManager(); - return entityManager; - } -*/ -/* - //@Override - public DBUser _verifyUser(@Nonnull BasicAuthClientCredentials aCredentials) throws UnknownUserException { - return null; - } - */ -} diff --git a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/data/dbms/model/DBOwnershipID.java b/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/data/dbms/model/DBOwnershipID.java deleted file mode 100644 index 50c17bc93c0437747a527c3a8797ff7dfb1f10b5..0000000000000000000000000000000000000000 --- a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/data/dbms/model/DBOwnershipID.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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.cipa.smp.server.data.dbms.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; - -import static eu.europa.ec.cipa.smp.server.data.dbms.model.CommonColumnsLengths.MAX_IDENTIFIER_SCHEME_LENGTH; -import static eu.europa.ec.cipa.smp.server.data.dbms.model.CommonColumnsLengths.MAX_PARTICIPANT_IDENTIFIER_VALUE_LENGTH; - -/** - * 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); - } - - @Column (name = "username", nullable = false, length = 256) - public String getUsername () { - return m_sUsername; - } - - public void setUsername (final String sUserName) { - m_sUsername = sUserName; - } - - @Column (name = "businessIdentifierScheme", nullable = false, length = 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 = 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 ()); - } - - @Transient - @Nonnull - public ParticipantIdentifierType asBusinessIdentifier () { - return new ParticipantIdentifierType(m_sParticipantIdentifierScheme, m_sParticipantIdentifier); - } -} diff --git a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/data/dbms/model/DBServiceGroup.java b/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/data/dbms/model/DBServiceGroup.java deleted file mode 100644 index 3d5b27798b7a758f610787d69826efc2a4f6df32..0000000000000000000000000000000000000000 --- a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/data/dbms/model/DBServiceGroup.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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.cipa.smp.server.data.dbms.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") -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; - } -} diff --git a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/data/dbms/model/DBServiceGroupID.java b/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/data/dbms/model/DBServiceGroupID.java deleted file mode 100644 index e2707d23b479330a93aa474b049b169966812aad..0000000000000000000000000000000000000000 --- a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/data/dbms/model/DBServiceGroupID.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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.cipa.smp.server.data.dbms.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; - -import static eu.europa.ec.cipa.smp.server.data.dbms.model.CommonColumnsLengths.MAX_IDENTIFIER_SCHEME_LENGTH; -import static eu.europa.ec.cipa.smp.server.data.dbms.model.CommonColumnsLengths.MAX_PARTICIPANT_IDENTIFIER_VALUE_LENGTH; - -/** - * ServiceGroupId == participant ID - * - * @author PEPPOL.AT, BRZ, Philip Helger - */ -@Embeddable -@ToString -@EqualsAndHashCode -public class DBServiceGroupID implements Serializable { - private String m_sParticipantIdentifierScheme; - private String m_sParticipantIdentifier; - - @Deprecated - public DBServiceGroupID () {} - - public DBServiceGroupID (@Nonnull final ParticipantIdentifierType aBusinessID) { - setBusinessIdentifierScheme (aBusinessID.getScheme ()); - setBusinessIdentifier (aBusinessID.getValue ()); - } - - @Column (name = "businessIdentifierScheme", nullable = false, length = 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 = MAX_PARTICIPANT_IDENTIFIER_VALUE_LENGTH) - public String getBusinessIdentifier () { - return m_sParticipantIdentifier; - } - - public void setBusinessIdentifier (final String sBusinessIdentifier) { - m_sParticipantIdentifier = sBusinessIdentifier; - } - - @Transient - @Nonnull - public ParticipantIdentifierType asBusinessIdentifier() { - return new ParticipantIdentifierType(m_sParticipantIdentifier, m_sParticipantIdentifierScheme); - } - -} diff --git a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/data/dbms/model/DBServiceMetadata.java b/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/data/dbms/model/DBServiceMetadata.java deleted file mode 100644 index f0a54206e3b2c85a63cef96384b6f0af433eb90b..0000000000000000000000000000000000000000 --- a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/data/dbms/model/DBServiceMetadata.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * 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.cipa.smp.server.data.dbms.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") -public class DBServiceMetadata implements Serializable { - - private DBServiceMetadataID m_aID; - private DBServiceGroup m_aServiceGroup; - private String m_sExtension; - private String m_sXmlContent; - - public DBServiceMetadata () {} - - public DBServiceMetadata (final DBServiceMetadataID aID, final DBServiceGroup aServiceGroup) { - m_aID = aID; - m_aServiceGroup = aServiceGroup; - } - - 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; - } - - @EmbeddedId - public DBServiceMetadataID getId () { - return m_aID; - } - - 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 m_aServiceGroup; - } - - public void setServiceGroup (final DBServiceGroup aServiceGroup) { - m_aServiceGroup = aServiceGroup; - } - - @Lob - @Column(name = "xmlcontent") - public String getXmlContent(){ - return m_sXmlContent; - } - - public void setXmlContent(String sXmlContent){ - m_sXmlContent = sXmlContent; - } - -} diff --git a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/data/dbms/model/DBServiceMetadataID.java b/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/data/dbms/model/DBServiceMetadataID.java deleted file mode 100644 index 4faf526ba61748ebe85ce5a9d9bc2d6876c4a312..0000000000000000000000000000000000000000 --- a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/data/dbms/model/DBServiceMetadataID.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * 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.cipa.smp.server.data.dbms.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; - -import static eu.europa.ec.cipa.smp.server.data.dbms.model.CommonColumnsLengths.*; - -/** - * ServiceMetadataId generated by hbm2java - * - * @author PEPPOL.AT, BRZ, Philip Helger - */ -@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 = 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 = 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 = 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 = 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); - } - -} diff --git a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/data/dbms/model/DBUser.java b/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/data/dbms/model/DBUser.java deleted file mode 100644 index 1d91995b5c23ba10b91e52757c3b2da4fcd94429..0000000000000000000000000000000000000000 --- a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/data/dbms/model/DBUser.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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.cipa.smp.server.data.dbms.model; - -import javax.persistence.*; -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 - */ -@Entity -@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 () {} - - @Id - @Column (name = "username", unique = true, nullable = false, length = 256) - public String getUsername () { - return m_sUserName; - } - - public void setUsername (final String sUserName) { - m_sUserName = sUserName; - } - - @Column (name = "password",length = 256) - public String getPassword () { - return m_sPassword; - } - - public void setPassword (final String sPassword) { - m_sPassword = sPassword; - } - - @Column(name = "isadmin", nullable = false) - public boolean isAdmin() { - return m_bIsAdmin; - } - - public void setAdmin(boolean isAdmin) { - m_bIsAdmin = isAdmin; - } - - @OneToMany (fetch = FetchType.LAZY, mappedBy = "user") - public Set <DBOwnership> getOwnerships () { - return m_aOwnerships; - } - - public void setOwnerships (final Set <DBOwnership> aOwnerships) { - m_aOwnerships = aOwnerships; - } -} diff --git a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/hook/PostRegistrationFilter.java b/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/hook/PostRegistrationFilter.java index 0a274c19b249777b745285fa1e592501d3844043..85b16d4aa42ac70d41445d4f3ee8fc60f095e95d 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/hook/PostRegistrationFilter.java +++ b/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/hook/PostRegistrationFilter.java @@ -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 { diff --git a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/security/KeyStoreUtils.java b/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/security/KeyStoreUtils.java index b20a335eb9ac3cb9b01bc58ea2d6ed173990ab1e..7c45c1a140fadb05ac2d55d58b6cc2553cb0aa14 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/security/KeyStoreUtils.java +++ b/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/security/KeyStoreUtils.java @@ -42,9 +42,6 @@ public final class KeyStoreUtils { /** The classpath entry referencing the global OpenPEPPOL truststore */ public static final String TRUSTSTORE_CLASSPATH_OPENPEPPOL = "truststore/global-truststore-openpeppol.jks"; - /** The password used to access the truststores */ - public static final String TRUSTSTORE_PASSWORD = "peppol"; - /** The truststore alias for the OpenPEPPOL root certificate */ public static final String TRUSTSTORE_ALIAS_ROOT_OPENPEPPOL = "peppol root ca"; @@ -120,8 +117,7 @@ public final class KeyStoreUtils { throw new IllegalArgumentException ("Failed to open key store '" + sKeyStorePath + "'", e); } } - if (aIS == null) - throw new IllegalArgumentException ("Failed to open key store '" + sKeyStorePath + "'"); + try { KeyStore aKeyStore = null; for (final String keystoreType : keystoreTypes) { @@ -140,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!"); } @@ -194,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 diff --git a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/services/BaseServiceGroupInterfaceImpl.java b/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/services/BaseServiceGroupInterfaceImpl.java index 56463c22414981ccdfdb1111457307be7b8f0e11..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/services/BaseServiceGroupInterfaceImpl.java +++ b/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/services/BaseServiceGroupInterfaceImpl.java @@ -1,104 +0,0 @@ -/* - * 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.cipa.smp.server.services; - - -import eu.europa.ec.cipa.smp.server.data.dbms.DBMSDataManager; -import eu.europa.ec.cipa.smp.server.errors.exceptions.NotFoundException; -import eu.europa.ec.smp.api.Identifiers; -import org.oasis_open.docs.bdxr.ns.smp._2016._05.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import javax.annotation.Nullable; -import java.util.ArrayList; - -/** - * This class implements the read-only methods for the REST ServiceGroup - * interface. It is used in the read-only interface and in the writable - * interface. - * - * @author PEPPOL.AT, BRZ, Philip Helger - */ -@Service -public final class BaseServiceGroupInterfaceImpl { - - private static final Logger s_aLogger = LoggerFactory.getLogger (BaseServiceGroupInterfaceImpl.class); - - @Autowired - private DBMSDataManager dataManager; - - /** - * @param sServiceGroupID - * Requested service group ID - * @throws Throwable - * in case of an error - */ - @Nullable - public ServiceGroup getServiceGroup(@Nullable final String sServiceGroupID) { - - s_aLogger.info (String.format("GET /%s",sServiceGroupID)); - - final ParticipantIdentifierType aServiceGroupID = Identifiers.asParticipantId(sServiceGroupID); - - final ObjectFactory aObjFactory = new ObjectFactory (); - - // Retrieve the service group - //final IDataManager aDataManager = DataManagerFactory.getInstance (); - final ServiceGroup aServiceGroup = dataManager.getServiceGroup (aServiceGroupID); - if (aServiceGroup == null) { - // No such service group - throw new NotFoundException(String.format("ServiceGroup '%s::%s' was not found", aServiceGroupID.getScheme(), aServiceGroupID.getValue())); - } - - aServiceGroup.setServiceMetadataReferenceCollection(new ServiceMetadataReferenceCollectionType(new ArrayList<ServiceMetadataReferenceType>())); - - // Then add the service metadata references - /* - final ServiceMetadataReferenceCollectionType aCollectionType = aObjFactory.createServiceMetadataReferenceCollectionType (); - final List <ServiceMetadataReferenceType> aMetadataReferences = aCollectionType.getServiceMetadataReferences(); - - final List <DBServiceMetadataID> aDocTypeIds = dataManager.getDocumentTypes (aServiceGroupID); - for (final DBServiceMetadataID aDocTypeId : aDocTypeIds) { - final ServiceMetadataReferenceType aMetadataReference = aObjFactory.createServiceMetadataReferenceType (); - - UriBuilder uriBuilder = aUriInfo.getBaseUriBuilder(); - if (configFile.getString ("contextPath.output", "false").equals ("false")) { - uriBuilder.replacePath (""); - } - XForwardedHttpHeadersHandler.applyReverseProxyParams(uriBuilder, httpHeaders); - String metadataHref = uriBuilder - .path (aServiceMetadataInterface) - .buildFromEncoded (IdentifierUtils.getIdentifierURIPercentEncoded (aDocTypeId.asBusinessIdentifier()), - IdentifierUtils.getIdentifierURIPercentEncoded (aDocTypeId.asDocumentTypeIdentifier())) - .toString(); - - aMetadataReference.setHref (metadataHref); - aMetadataReferences.add (aMetadataReference); - } - aServiceGroup.setServiceMetadataReferenceCollection (aCollectionType); - */ - - s_aLogger.info (String.format("Finished getServiceGroup(%s)", sServiceGroupID)); - - /* - * Finally return it - */ - return aServiceGroup; - } - -} diff --git a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/services/BaseServiceMetadataInterfaceImpl.java b/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/services/BaseServiceMetadataInterfaceImpl.java deleted file mode 100644 index b088555260c732200e890f15fdd3a0b9476afc2c..0000000000000000000000000000000000000000 --- a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/services/BaseServiceMetadataInterfaceImpl.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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.cipa.smp.server.services; - -import eu.europa.ec.cipa.smp.server.conversion.ServiceMetadataConverter; -import eu.europa.ec.cipa.smp.server.data.dbms.DBMSDataManager; -import eu.europa.ec.cipa.smp.server.data.dbms.model.DBServiceMetadataID; -import eu.europa.ec.cipa.smp.server.errors.exceptions.NotFoundException; -import eu.europa.ec.cipa.smp.server.util.SignatureFilter; -import eu.europa.ec.smp.api.Identifiers; -import org.oasis_open.docs.bdxr.ns.smp._2016._05.DocumentIdentifier; -import org.oasis_open.docs.bdxr.ns.smp._2016._05.ParticipantIdentifierType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.w3c.dom.Document; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.util.ArrayList; -import java.util.List; - -/** - * This class implements the read-only methods for the REST - * SignedServiceMetadata interface. It is used in the read-only interface and in - * the writable interface. - * - * @author PEPPOL.AT, BRZ, Philip Helger - */ -@Service -public final class BaseServiceMetadataInterfaceImpl { - private static final Logger s_aLogger = LoggerFactory.getLogger (BaseServiceMetadataInterfaceImpl.class); - - private BaseServiceMetadataInterfaceImpl () {} - - @Autowired - private DBMSDataManager dataManager; - - @Autowired - SignatureFilter signatureFilter; - - @Nonnull - public Document getServiceRegistration (@Nullable final String sServiceGroupID, - @Nullable final String sDocumentTypeID){ - s_aLogger.info (String.format("GET /%s/services/%s", sServiceGroupID, sDocumentTypeID)); - - final ParticipantIdentifierType aServiceGroupID = Identifiers.asParticipantId(sServiceGroupID); - final DocumentIdentifier aDocTypeID = Identifiers.asDocumentId (sDocumentTypeID); - - //final IDataManager aDataManager = DataManagerFactory.getInstance (); - String sServiceMetadata = dataManager.getService (aServiceGroupID, aDocTypeID); - if(sServiceMetadata == null) { - throw new NotFoundException(String.format("Service '%s/services/%s' was not found", sServiceGroupID, sDocumentTypeID)); - } - - Document aSignedServiceMetadata = ServiceMetadataConverter.toSignedServiceMetadatadaDocument(sServiceMetadata); - - signatureFilter.sign(aSignedServiceMetadata); - - s_aLogger.info (String.format("Finished getServiceRegistration(%s,%s)", sServiceGroupID, sDocumentTypeID)); - return aSignedServiceMetadata; - } - - public List<DocumentIdentifier> getMetadataIdentifiers(String serviceGroupId) { - ParticipantIdentifierType participantId = Identifiers.asParticipantId(serviceGroupId); - List<DBServiceMetadataID> metadataIds = null; - try { - metadataIds = dataManager.getDocumentTypes(participantId); - } catch (Throwable throwable) { - throw new RuntimeException(throwable); - } - - List<DocumentIdentifier> documentIdentifierTypes = new ArrayList(); - for (DBServiceMetadataID metadataId : metadataIds) { - DocumentIdentifier docId = new DocumentIdentifier(metadataId.getDocumentTypeIdentifier(), metadataId.getDocumentTypeIdentifierScheme()); - documentIdentifierTypes.add(docId); - } - return documentIdentifierTypes; - } -} diff --git a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/util/BusdoxURLUtils.java b/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/util/BusdoxURLUtils.java deleted file mode 100644 index 93fba3041f4fd841de6b1ddf2a37a8ed48f6ff6b..0000000000000000000000000000000000000000 --- a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/util/BusdoxURLUtils.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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.cipa.smp.server.util; - -import javax.annotation.Nullable; -import javax.annotation.concurrent.Immutable; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; - -/** - * Utility methods for assembling URLs and URL elements required for BusDox. - * - * @author PEPPOL.AT, BRZ, Philip Helger - */ -@Immutable -@Deprecated -//TODO: Remove me -public final class BusdoxURLUtils { - //public static final Charset URL_CHARSET = Charset.forName("UTF-8"); - //public static final Locale URL_LOCALE = Locale.US; - - - private static final BusdoxURLUtils s_aInstance = new BusdoxURLUtils (); - - private BusdoxURLUtils() {} - - /** - * Escape the passed URL to use the percentage maskings. - * - * @param sURL - * The input URL or URL part. May be <code>null</code>. - * @return <code>null</code> if the input string was <code>null</code>. - */ - @Nullable - public static String createPercentEncodedURL (@Nullable final String sURL) { - if (sURL != null) - //return new URLCodec ().encodeText (sURL); - try { - return URLEncoder.encode(sURL, "UTF-8"); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } - return null; - } - -} diff --git a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/util/CertificateUtils.java b/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/util/CertificateUtils.java index dc022ea4796909f4f5a5a978c9d6df038e14e621..615233f7da3bbbe40089ea265ce85f4dc4c4b33b 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/util/CertificateUtils.java +++ b/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/util/CertificateUtils.java @@ -15,7 +15,7 @@ package eu.europa.ec.cipa.smp.server.util; -import eu.europa.ec.cipa.smp.server.errors.exceptions.CertificateAuthenticationException; +import eu.europa.ec.edelivery.smp.exceptions.CertificateAuthenticationException; import eu.europa.ec.cipa.smp.server.security.CertificateDetails; import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.StringUtils; diff --git a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/util/IdentifierUtils.java b/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/util/IdentifierUtils.java index cb86e2d0de4cd081f442df895f70b3217bffb2b7..b4a905d08c1db28f20587f58b0a4fd8bedd0b1b8 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/util/IdentifierUtils.java +++ b/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/util/IdentifierUtils.java @@ -23,7 +23,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; -import static eu.europa.ec.cipa.smp.server.data.dbms.model.CommonColumnsLengths.URL_SCHEME_VALUE_SEPARATOR; +import static eu.europa.ec.edelivery.smp.data.model.CommonColumnsLengths.URL_SCHEME_VALUE_SEPARATOR; /** * This class contains several identifier related utility methods. @@ -170,23 +170,4 @@ public final class IdentifierUtils { // Combine scheme and value return sScheme + URL_SCHEME_VALUE_SEPARATOR + sValue; } - - /** - * Get the identifier suitable for an URI and percent encoded. - * - * @param aIdentifier - * The identifier to be encoded. May not be <code>null</code>. - * @return Never <code>null</code>. - */ - @Nonnull - public static String getIdentifierURIPercentEncoded (@Nonnull final ParticipantIdentifierType aIdentifier) { - final String sURIEncoded = getIdentifierURIEncoded (aIdentifier); - return BusdoxURLUtils.createPercentEncodedURL (sURIEncoded); - } - - @Nonnull - public static String getIdentifierURIPercentEncoded (@Nonnull final DocumentIdentifier aIdentifier) { - final String sURIEncoded = getIdentifierURIEncoded (aIdentifier); - return BusdoxURLUtils.createPercentEncodedURL (sURIEncoded); - } } diff --git a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/util/LogStartupListener.java b/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/util/LogStartupListener.java deleted file mode 100644 index fae12e27d4ef6cd8f7bf30894432a3d582b04f95..0000000000000000000000000000000000000000 --- a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/util/LogStartupListener.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.cipa.smp.server.util; - -import javax.annotation.Nonnull; -import javax.annotation.concurrent.Immutable; -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * This class is used for logging startup and shutdown - * - * @author PEPPOL.AT, BRZ, Philip Helger - */ -@Immutable -public final class LogStartupListener implements ServletContextListener { - private static final Logger s_aLogger = LoggerFactory.getLogger (LogStartupListener.class); - - public void contextInitialized (@Nonnull final ServletContextEvent aServletContextEvent) { - s_aLogger.info ("SMP context started"); - } - - public void contextDestroyed (@Nonnull final ServletContextEvent aServletContextEvent) { - s_aLogger.info ("SMP context stopped"); - } -} diff --git a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/util/SMPDBUtils.java b/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/util/SMPDBUtils.java deleted file mode 100644 index a0782657d91a3119c70d0980c32da156e61d7dec..0000000000000000000000000000000000000000 --- a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/util/SMPDBUtils.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * 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.cipa.smp.server.util; - -import org.oasis_open.docs.bdxr.ns.smp._2016._05.ObjectFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.annotation.concurrent.Immutable; - -/** - * This class is used inside the DB component and contains several utility - * methods. - * - * @author PEPPOL.AT, BRZ, Philip Helger - */ -@Immutable -@Deprecated -public final class SMPDBUtils { - - private static final Logger s_aLogger = LoggerFactory.getLogger(SMPDBUtils.class); - private static final ObjectFactory s_aOF = new ObjectFactory(); - //private static final XMLWriterSettings s_aXWS = new XMLWriterSettings().setSerializeDocType(EXMLSerializeDocType.IGNORE).setIndent(EXMLSerializeIndent.NONE); - - private SMPDBUtils() { - } - - /** - * This class is used for converting between a String representation of the - * extension element and the "ExtensionType" complex type. - * - * @author PEPPOL.AT, BRZ, Philip Helger - * - - @Nullable - @Deprecated - public static ExtensionType getAsExtensionSafe(@Nullable final String sXML) { - try { - if (StringHelper.hasText(sXML)) { - - // Try to interpret as XML - final Document aDoc = DOMReader.readXMLDOM(sXML); - if (aDoc != null) { - final ExtensionType aExtension = s_aOF.createExtensionType(); - aExtension.setAny(aDoc.getDocumentElement()); - return aExtension; - } - } - } catch (SAXException | IllegalArgumentException ex) { - s_aLogger.warn("Error in parsing extension XML '" + sXML + "'", ex); - } - return null; - } -*/ - /** - * Convert the passed extension type to a string representation. - * - * @param aExtension - * The extension to be converted. May be <code>null</code>. - * @return <code>null</code> if no extension was passed - the XML - * representation of the extension otherwise. - * @throws IllegalArgumentException - * If the Extension cannot be converted to a String - * - @Nullable - @Deprecated - public static String convert (@Nullable final ExtensionType aExtension) { - // If there is no extension present, nothing to convert - if (aExtension == null) - return null; - - // Get the extension content - final Object aExtensionElement = aExtension.getAny (); - if (aExtensionElement == null) - return null; - - // Handle DOM nodes directly - if (aExtensionElement instanceof Node) - return XMLWriter.getNodeAsString ((Node) aExtensionElement, s_aXWS); - - // Handle Micro nodes also directly - if (aExtensionElement instanceof IMicroNode) - return MicroWriter.getNodeAsString ((IMicroNode) aExtensionElement, s_aXWS); - - try { - // Call the global type converter - maybe it helps :) - return TypeConverter.convertIfNecessary (aExtensionElement, String.class); - } - catch (final TypeConverterException ex) { - // FIXME the extension may contain multiple elements (e.g. lists) - throw new IllegalArgumentException ("Don't know how to convert the extension element of type " + - aExtension.getClass ().getName ()); - } - } -*/ - /** - * The certificate string needs to be emitted in portions of 64 characters. If - * characters are left, than <CR><LF> ("\r\n") must be added to the - * string so that the next characters start on a new line. After the last - * part, no <CR><LF> is needed. Respective RFC parts are 1421 4.3.2.2 - * and 4.3.2.4 - * - * @param sCertificate - * Original certificate string as stored in the DB - * @return The RFC 1421 compliant string - * - @Nullable - public static String getRFC1421CompliantStringWithoutCarriageReturnCharacters(@Nullable final String sCertificate) { - if (StringHelper.hasNoText(sCertificate)) - return sCertificate; - - // Remove all existing whitespace characters - String sPlainString = StringHelper.getWithoutAnySpaces(sCertificate); - - // Start building the result - final int nMaxLineLength = 64; - final String sLF = "\n"; //Originally RFC suggests CRLF instead of LF - final StringBuilder aSB = new StringBuilder(); - while (sPlainString.length() > nMaxLineLength) { - // Append line + LF - aSB.append(sPlainString, 0, nMaxLineLength).append(sLF); - - // Remove the start of the string - sPlainString = sPlainString.substring(nMaxLineLength); - } - - // Append the rest - aSB.append(sPlainString); - - return aSB.toString(); - } - */ -} diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/BaseDao.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/BaseDao.java new file mode 100644 index 0000000000000000000000000000000000000000..e0faa253d70df1f9890695832f9555a913945b53 --- /dev/null +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/BaseDao.java @@ -0,0 +1,67 @@ +/* + * 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.dao; + +import org.springframework.core.GenericTypeResolver; + +import javax.persistence.EntityExistsException; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import java.io.Serializable; + +/** + * Created by gutowpa on 24/11/2017. + */ +public abstract class BaseDao<E extends Serializable> { + + @PersistenceContext + protected EntityManager em; + + private final Class<E> entityClass; + + public BaseDao() { + entityClass = (Class<E>) GenericTypeResolver.resolveTypeArgument(getClass(), BaseDao.class); + } + + public E find(Object primaryKey) { + return em.find(entityClass, primaryKey); + } + + public void save(E entity) { + try { + em.persist(entity); + } catch(EntityExistsException e){ + em.merge(entity); + } + } + + public void remove(E entity) { + em.remove(entity); + } + + /** + * Removes Entity by given primary key + * + * @return true if entity existed before and was removed in this call. + * False if entity did not exist, so nothing was changed + */ + public boolean removeById(Object primaryKey) { + int removedRecords = em.createQuery("delete from " + entityClass.getName() + " e where e.id = :primaryKey") + .setParameter("primaryKey", primaryKey) + .executeUpdate(); + return removedRecords > 0; + } +} diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/OwnershipDao.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/OwnershipDao.java new file mode 100644 index 0000000000000000000000000000000000000000..2a4ac0b9adba90422c8e6a49d90b2f7a5b617ebb --- /dev/null +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/OwnershipDao.java @@ -0,0 +1,35 @@ +/* + * 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.dao; + +import eu.europa.ec.edelivery.smp.data.model.DBOwnership; +import eu.europa.ec.edelivery.smp.data.model.DBServiceGroupId; +import org.springframework.stereotype.Repository; + +/** + * Created by gutowpa on 14/11/2017. + */ +@Repository +public class OwnershipDao extends BaseDao<DBOwnership>{ + + public void removeByServiceGroupId(DBServiceGroupId serviceGroupID) { + em.createQuery("DELETE FROM DBOwnership o WHERE o.id.businessIdentifierScheme = :scheme and o.id.businessIdentifier = :id") + .setParameter("scheme", serviceGroupID.getBusinessIdentifierScheme()) + .setParameter("id", serviceGroupID.getBusinessIdentifier()) + .executeUpdate(); + } + +} diff --git a/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/errors/exceptions/XmlParsingExceptionTest.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/ServiceGroupDao.java similarity index 51% rename from smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/errors/exceptions/XmlParsingExceptionTest.java rename to smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/ServiceGroupDao.java index e27a7ecfdbf5cd1b00ae9c34fa9b7f8b1d200c64..36ab5d1cfdad1b45e82871c6ed4f4cf95a0bdd7b 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/errors/exceptions/XmlParsingExceptionTest.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/ServiceGroupDao.java @@ -13,34 +13,14 @@ * See the Licence for the specific language governing permissions and limitations under the Licence. */ -package eu.europa.ec.cipa.smp.server.errors.exceptions; +package eu.europa.ec.edelivery.smp.data.dao; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import eu.europa.ec.edelivery.smp.data.model.DBServiceGroup; +import org.springframework.stereotype.Repository; /** - * Created by migueti on 16/01/2017. + * Created by gutowpa on 14/11/2017. */ -public class XmlParsingExceptionTest { - - @Test - public void testXmlParsingExceptionThrown() { - // given - - // when - try { - throwXmlParsingException(); - } catch(XmlParsingException ex) { - // then - assertEquals("java.lang.Exception: Parent Exception", ex.getMessage()); - return; - } - fail(); - } - - private void throwXmlParsingException() { - throw new XmlParsingException(new Exception("Parent Exception")); - } +@Repository +public class ServiceGroupDao extends BaseDao<DBServiceGroup> { } diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/ServiceMetadataDao.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/ServiceMetadataDao.java new file mode 100644 index 0000000000000000000000000000000000000000..d6a27dcb41b3aa0a2d198381afc864cf0545e966 --- /dev/null +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/ServiceMetadataDao.java @@ -0,0 +1,38 @@ +/* + * 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.dao; + +import eu.europa.ec.edelivery.smp.data.model.DBServiceMetadata; +import eu.europa.ec.edelivery.smp.data.model.DBServiceMetadataId; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * Created by gutowpa on 14/11/2017. + */ +@Repository +public class ServiceMetadataDao extends BaseDao<DBServiceMetadata> { + + public List<DBServiceMetadataId> findIdsByServiceGroup(String participantIdScheme, + String participantIdValue) { + + return em.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(); + } +} diff --git a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/security/UserRole.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/UserDao.java similarity index 75% rename from smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/security/UserRole.java rename to smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/UserDao.java index 94ecc342f2ea0d00e3a4d49685ba95dc3830b398..9ec88083b881be9be4c6755518cbdd896b67e513 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/security/UserRole.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/UserDao.java @@ -13,13 +13,14 @@ * See the Licence for the specific language governing permissions and limitations under the Licence. */ -package eu.europa.ec.cipa.smp.server.security; +package eu.europa.ec.edelivery.smp.data.dao; + +import eu.europa.ec.edelivery.smp.data.model.DBUser; +import org.springframework.stereotype.Repository; /** - * Created by gutowpa on 27/01/2017. + * Created by gutowpa on 14/11/2017. */ -public enum UserRole { - ROLE_SMP_ADMIN, - ROLE_SERVICEGROUP_ADMIN, - ROLE_ANONYMOUS +@Repository +public class UserDao extends BaseDao<DBUser> { } diff --git a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/data/dbms/model/CommonColumnsLengths.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/CommonColumnsLengths.java similarity index 76% rename from smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/data/dbms/model/CommonColumnsLengths.java rename to smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/CommonColumnsLengths.java index ead252458c8317ecb105d189fc3530e2f8f78b27..fbec59238109a45955a8d3da004a6559a274dc48 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/data/dbms/model/CommonColumnsLengths.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/CommonColumnsLengths.java @@ -13,7 +13,7 @@ * See the Licence for the specific language governing permissions and limitations under the Licence. */ -package eu.europa.ec.cipa.smp.server.data.dbms.model; +package eu.europa.ec.edelivery.smp.data.model; /** * Created by gutowpa on 01/02/2017. @@ -22,8 +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 String DEFAULT_PARTICIPANT_IDENTIFIER_SCHEME = "iso6523-actorid-upis"; - public static final String DEFAULT_DOCUMENT_TYPE_IDENTIFIER_SCHEME = "busdox-docid-qns"; - public static final String DEFAULT_PROCESS_IDENTIFIER_SCHEME = "cenbii-procid-ubl"; + public static final int MAX_USERNAME_LENGTH = 256; public static final String URL_SCHEME_VALUE_SEPARATOR = "::"; } diff --git a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/data/dbms/model/DBOwnership.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBOwnership.java similarity index 68% rename from smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/data/dbms/model/DBOwnership.java rename to smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBOwnership.java index 5af38de857a1daf26e6a010535b5ca15ba9bbf87..b39a5dd20e87c3572ecc3409708c09c5ebd09401 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/data/dbms/model/DBOwnership.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBOwnership.java @@ -12,49 +12,37 @@ * 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.cipa.smp.server.data.dbms.model; + +package eu.europa.ec.edelivery.smp.data.model; import javax.persistence.*; import java.io.Serializable; -/** - * Define the ownership of a service group -> 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; + public DBOwnershipId getId () { + 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) @@ -69,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; } } diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBOwnershipId.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBOwnershipId.java new file mode 100644 index 0000000000000000000000000000000000000000..a6bc958ce389f63de7bc7e27c4e303b08907cc0f --- /dev/null +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBOwnershipId.java @@ -0,0 +1,69 @@ +/* + * 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 javax.persistence.Column; +import javax.persistence.Embeddable; +import java.io.Serializable; + +@Embeddable +@ToString +@EqualsAndHashCode +public class DBOwnershipId implements Serializable { + + private String username; + private String participantIdScheme; + private String participantIdValue; + + public DBOwnershipId() { + } + + public DBOwnershipId(String userName, String participantIdScheme, String participantIdValue) { + username = userName; + setBusinessIdentifierScheme(participantIdScheme); + setBusinessIdentifier(participantIdValue); + } + + @Column(name = "username", nullable = false, length = 256) + public String getUsername() { + return username; + } + + @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 participantIdValue; + } + + public void setUsername(final String sUserName) { + username = sUserName; + } + + public void setBusinessIdentifierScheme(final String sBusinessIdentifierScheme) { + participantIdScheme = sBusinessIdentifierScheme; + } + + public void setBusinessIdentifier(final String sBusinessIdentifier) { + participantIdValue = sBusinessIdentifier; + } +} diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceGroup.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceGroup.java new file mode 100644 index 0000000000000000000000000000000000000000..ea564e9f849b77cfecd917ac546b20f720fc52f9 --- /dev/null +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceGroup.java @@ -0,0 +1,86 @@ +/* + * 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; +import java.util.HashSet; +import java.util.Set; + +@Entity +@Table(name = "smp_service_group") +public class DBServiceGroup implements Serializable { + + 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; + } +} diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceGroupId.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceGroupId.java new file mode 100644 index 0000000000000000000000000000000000000000..1a1767d21504ba121ed446bc87c456d5bb5645a5 --- /dev/null +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceGroupId.java @@ -0,0 +1,64 @@ +/* + * 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 javax.persistence.Column; +import javax.persistence.Embeddable; +import java.io.Serializable; + +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 participantIdScheme; + private String participantIdValue; + + public DBServiceGroupId() { + } + + public DBServiceGroupId(String participantIdScheme, + String participantIdValue) { + + setBusinessIdentifierScheme(participantIdScheme); + setBusinessIdentifier(participantIdValue); + } + + @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; + } + + public void setBusinessIdentifierScheme(String participantIdScheme) { + this.participantIdScheme = participantIdScheme; + } + + public void setBusinessIdentifier(String participantIdValue) { + this.participantIdValue = participantIdValue; + } + +} diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceMetadata.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceMetadata.java new file mode 100644 index 0000000000000000000000000000000000000000..aa40efe49fbc9adde8d655e6af33df0b3752e709 --- /dev/null +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceMetadata.java @@ -0,0 +1,81 @@ +/* + * 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; + +@Entity +@Table(name = "smp_service_metadata") +public class DBServiceMetadata implements Serializable { + + private DBServiceMetadataId serviceMetadataId; + private DBServiceGroup serviceGroup; + private String xmlContent; + + public DBServiceMetadata() { } + + public DBServiceMetadata(DBServiceMetadataId serviceMetadataId, DBServiceGroup serviceGroup) { + this(serviceMetadataId, serviceGroup, null); + } + + public DBServiceMetadata(DBServiceMetadataId serviceMetadataId, + DBServiceGroup serviceGroup, + String xmlContent) { + this.serviceMetadataId = serviceMetadataId; + this.serviceGroup = serviceGroup; + this.xmlContent = xmlContent; + } + + @EmbeddedId + public DBServiceMetadataId getId() { + return serviceMetadataId; + } + + @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; + } + + @Lob + @Column(name = "xmlcontent") + public String getXmlContent() { + return xmlContent; + } + + public void setId(final DBServiceMetadataId serviceMetadataId) { + this.serviceMetadataId = serviceMetadataId; + } + + public void setServiceGroup(final DBServiceGroup serviceGroup) { + this.serviceGroup = serviceGroup; + } + + public void setXmlContent(String xmlContent) { + this.xmlContent = xmlContent; + } + +} diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceMetadataId.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceMetadataId.java new file mode 100644 index 0000000000000000000000000000000000000000..83be66e289d72ade3299969257287417fd033b6a --- /dev/null +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceMetadataId.java @@ -0,0 +1,87 @@ +/* + * 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 javax.persistence.Column; +import javax.persistence.Embeddable; +import java.io.Serializable; + +import static eu.europa.ec.edelivery.smp.data.model.CommonColumnsLengths.*; + +@Embeddable +@ToString +@EqualsAndHashCode +public class DBServiceMetadataId implements Serializable { + + 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; + } +} diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBUser.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBUser.java new file mode 100644 index 0000000000000000000000000000000000000000..fe5c3ae79d61dd3a68109b0ee6c5b2f94f2a14eb --- /dev/null +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBUser.java @@ -0,0 +1,73 @@ +/* + * 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; +import java.util.HashSet; +import java.util.Set; + +import static eu.europa.ec.edelivery.smp.data.model.CommonColumnsLengths.MAX_USERNAME_LENGTH; + +@Entity +@Table(name = "smp_user") +public class DBUser implements Serializable { + + 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; + } + + @Column(name = "password", length = MAX_USERNAME_LENGTH) + public String getPassword() { + return password; + } + + + @Column(name = "isadmin", nullable = false) + public boolean isAdmin() { + return isAdmin; + } + + @OneToMany(fetch = FetchType.LAZY, mappedBy = "user") + public Set<DBOwnership> getOwnerships() { + return ownerships; + } + + public void setUsername(String username) { + this.username = username; + } + + public void setPassword(String password) { + this.password = password; + } + + public void setAdmin(boolean isAdmin) { + this.isAdmin = isAdmin; + } + + public void setOwnerships(Set<DBOwnership> ownerships) { + this.ownerships = ownerships; + } +} diff --git a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/errors/exceptions/CertificateAuthenticationException.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/exceptions/CertificateAuthenticationException.java similarity index 94% rename from smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/errors/exceptions/CertificateAuthenticationException.java rename to smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/exceptions/CertificateAuthenticationException.java index 6f352526d4e73d0e8685caf17e453c45e752fe5b..29d47705bbb7a6f8db8dd7b4a955b9d6257f2db6 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/errors/exceptions/CertificateAuthenticationException.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/exceptions/CertificateAuthenticationException.java @@ -13,7 +13,7 @@ * See the Licence for the specific language governing permissions and limitations under the Licence. */ -package eu.europa.ec.cipa.smp.server.errors.exceptions; +package eu.europa.ec.edelivery.smp.exceptions; public class CertificateAuthenticationException extends Exception { diff --git a/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/errors/exceptions/NotFoundExceptionTest.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/exceptions/ConversionException.java similarity index 53% rename from smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/errors/exceptions/NotFoundExceptionTest.java rename to smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/exceptions/ConversionException.java index e87556fbea928c34aba3181f5b5947ecfe6e95d1..03b6aa9444945a087f3fe17e566139bca3ff3d40 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/errors/exceptions/NotFoundExceptionTest.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/exceptions/ConversionException.java @@ -13,34 +13,18 @@ * See the Licence for the specific language governing permissions and limitations under the Licence. */ -package eu.europa.ec.cipa.smp.server.errors.exceptions; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +package eu.europa.ec.edelivery.smp.exceptions; /** - * Created by migueti on 16/01/2017. + * Thrown when entity cannot be converted. + * Means that user's input hasn't been validated properly or data in database are malformed. + * In both cases most probably environment or source code issue occured (bug). + * <p> + * Created by gutowpa on 15/11/2017. */ -public class NotFoundExceptionTest { - - @Test - public void testNotFoundExceptionThrown() { - // given - - // when - try { - throwNotFoundException(); - } catch (NotFoundException ex) { - // then - assertEquals("Exception thrown", ex.getMessage()); - return; - } - fail(); - } +public class ConversionException extends IllegalStateException { - private void throwNotFoundException() { - throw new NotFoundException("Exception thrown"); + public ConversionException(Exception e){ + super(e); } } diff --git a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/errors/exceptions/NotFoundException.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/exceptions/NotFoundException.java similarity index 78% rename from smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/errors/exceptions/NotFoundException.java rename to smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/exceptions/NotFoundException.java index 9a7d406c150f1995702f0758bd650bc3f6925000..26236ec4e5e80344d3db947a8e50ecefecf264da 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/errors/exceptions/NotFoundException.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/exceptions/NotFoundException.java @@ -13,15 +13,19 @@ * See the Licence for the specific language governing permissions and limitations under the Licence. */ -package eu.europa.ec.cipa.smp.server.errors.exceptions; +package eu.europa.ec.edelivery.smp.exceptions; /** * Created by migueti on 13/01/2017. */ public class NotFoundException extends RuntimeException { - public NotFoundException (final String sMsg) { - super (sMsg); + public NotFoundException(String msg) { + super(msg); + } + + public NotFoundException(String msgFormat, Object... params) { + this(String.format(msgFormat, params)); } } diff --git a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/errors/exceptions/UnknownUserException.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/exceptions/UnknownUserException.java similarity index 64% rename from smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/errors/exceptions/UnknownUserException.java rename to smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/exceptions/UnknownUserException.java index 254e05394604579c4396017db65d416f6e5c492e..6a04c6789263a3da1e8f3f61ed169651e89e855f 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/errors/exceptions/UnknownUserException.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/exceptions/UnknownUserException.java @@ -12,29 +12,16 @@ * 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.cipa.smp.server.errors.exceptions; -import javax.annotation.Nullable; +package eu.europa.ec.edelivery.smp.exceptions; /** * This exceptions is thrown if the provided user name does not exist. - * - * @author PEPPOL.AT, BRZ, Philip Helger */ public class UnknownUserException extends RuntimeException { - private final String m_sUserName; - - public UnknownUserException (@Nullable final String sUserName) { - super ("Unknown user '" + sUserName + "'"); - m_sUserName = sUserName; - } + public UnknownUserException(String username) { + super("Unknown user '" + username + "'"); + } - /** - * @return The user name which was not found. May be <code>null</code>. - */ - @Nullable - public String getUserName () { - return m_sUserName; - } } diff --git a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/errors/exceptions/XmlParsingException.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/exceptions/XmlParsingException.java similarity index 94% rename from smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/errors/exceptions/XmlParsingException.java rename to smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/exceptions/XmlParsingException.java index 64284a11f369ec190746af61ae78226e4f5f3b96..b8ed6d76ee694e9432e7851bee07492dce5793ad 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/errors/exceptions/XmlParsingException.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/exceptions/XmlParsingException.java @@ -13,7 +13,7 @@ * See the Licence for the specific language governing permissions and limitations under the Licence. */ -package eu.europa.ec.cipa.smp.server.errors.exceptions; +package eu.europa.ec.edelivery.smp.exceptions; /** * Occurs when tried to parse malformed XML message. diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ServiceGroupService.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ServiceGroupService.java new file mode 100644 index 0000000000000000000000000000000000000000..6ad61bf294a9f75fd1af9034f0ea3cc89673c8f9 --- /dev/null +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ServiceGroupService.java @@ -0,0 +1,133 @@ +/* + * 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.services; + +import eu.europa.ec.cipa.smp.server.conversion.CaseSensitivityNormalizer; +import eu.europa.ec.cipa.smp.server.conversion.ServiceGroupConverter; +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; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.lang.reflect.Array; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +import static eu.europa.ec.cipa.smp.server.conversion.ServiceGroupConverter.toDbModel; +import static eu.europa.ec.smp.api.Identifiers.asString; +import static java.util.Arrays.asList; + +/** + * Created by gutowpa on 14/11/2017. + */ +@Service +public class ServiceGroupService { + + private static final Logger log = LoggerFactory.getLogger(ServiceGroupService.class); + + @Autowired + private CaseSensitivityNormalizer caseSensitivityNormalizer; + + @Autowired + private ServiceGroupDao serviceGroupDao; + + @Autowired + private UserDao userDao; + + @Autowired + private IRegistrationHook m_aHook; + + public ServiceGroup getServiceGroup(ParticipantIdentifierType serviceGroupId) { + ParticipantIdentifierType normalizedServiceGroupId = caseSensitivityNormalizer.normalize(serviceGroupId); + + DBServiceGroup dbServiceGroup = serviceGroupDao.find(toDbModel(normalizedServiceGroupId)); + if (dbServiceGroup == null) { + throw new NotFoundException("ServiceGroup not found: '%s'", asString(serviceGroupId)); + } + return ServiceGroupConverter.toServiceGroup(dbServiceGroup); + } + + @Transactional + public boolean saveServiceGroup(ServiceGroup serviceGroup, String newOwnerName) { + ServiceGroup normalizedServiceGroup = normalizeIdentifierCaseSensitivity(serviceGroup); + ParticipantIdentifierType normalizedParticipantId = normalizedServiceGroup.getParticipantIdentifier(); + + DBUser newOwner = userDao.find(newOwnerName); + if (newOwner == null) { + throw new UnknownUserException(newOwnerName); + } + + DBServiceGroup dbServiceGroup = serviceGroupDao.find(toDbModel(normalizedParticipantId)); + + String extensions = ServiceGroupConverter.extractExtensionsPayload(normalizedServiceGroup); + + if (dbServiceGroup != null) { + dbServiceGroup.setExtension(extensions); + serviceGroupDao.save(dbServiceGroup); + return false; + } else { + // Register in SML (DNS) + m_aHook.create(normalizedParticipantId); + + //Save ServiceGroup + dbServiceGroup = new DBServiceGroup(new DBServiceGroupId(normalizedParticipantId.getScheme(), normalizedParticipantId.getValue())); + dbServiceGroup.setExtension(extensions); + + // Save the ownership information + DBOwnershipId dbOwnershipID = new DBOwnershipId(newOwnerName, normalizedParticipantId.getScheme(), normalizedParticipantId.getValue()); + DBOwnership dbOwnership = new DBOwnership(dbOwnershipID, newOwner, dbServiceGroup); + dbServiceGroup.setOwnerships(new HashSet(asList(dbOwnership))); + //ownershipDao.save(ownership); + serviceGroupDao.save(dbServiceGroup); + return true; + } + } + + + private ServiceGroup normalizeIdentifierCaseSensitivity(ServiceGroup serviceGroup) { + final ServiceGroup sg = new ServiceGroup(); + sg.setParticipantIdentifier(caseSensitivityNormalizer.normalize(serviceGroup.getParticipantIdentifier())); + sg.setServiceMetadataReferenceCollection(serviceGroup.getServiceMetadataReferenceCollection()); + sg.getExtensions().addAll(serviceGroup.getExtensions()); + return sg; + } + + @Transactional + public void deleteServiceGroup(ParticipantIdentifierType serviceGroupId) { + final ParticipantIdentifierType normalizedServiceGroupId = caseSensitivityNormalizer.normalize(serviceGroupId); + + DBServiceGroup dbServiceGroup = serviceGroupDao.find(toDbModel(normalizedServiceGroupId)); + if (dbServiceGroup == null) { + throw new NotFoundException("ServiceGroup not found: '%s'", asString(serviceGroupId)); + } + + //ownershipDao.removeByServiceGroupId(dbServiceGroup.getId()); + serviceGroupDao.remove(dbServiceGroup); + + m_aHook.delete(normalizedServiceGroupId); + } +} diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ServiceMetadataService.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ServiceMetadataService.java new file mode 100644 index 0000000000000000000000000000000000000000..971a7b811e09004c25fa23b9444dce9e31b293bc --- /dev/null +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ServiceMetadataService.java @@ -0,0 +1,126 @@ +/* + * 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.services; + +import eu.europa.ec.cipa.smp.server.conversion.CaseSensitivityNormalizer; +import eu.europa.ec.cipa.smp.server.conversion.ServiceGroupConverter; +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.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.w3c.dom.Document; + +import java.util.ArrayList; +import java.util.List; + +import static eu.europa.ec.cipa.smp.server.conversion.ServiceMetadataConverter.toDbModel; +import static eu.europa.ec.cipa.smp.server.conversion.ServiceMetadataConverter.toSignedServiceMetadatadaDocument; +import static eu.europa.ec.smp.api.Identifiers.asString; + +/** + * Created by gutowpa on 14/11/2017. + */ +@Service +public class ServiceMetadataService { + + @Autowired + private CaseSensitivityNormalizer caseSensitivityNormalizer; + + @Autowired + private ServiceMetadataDao serviceMetadataDao; + + @Autowired + private ServiceGroupDao serviceGroupDao; + + @Autowired + private SignatureFilter signatureFilter; + + public Document getServiceMetadataDocument(ParticipantIdentifierType serviceGroupId, DocumentIdentifier documentId) { + ParticipantIdentifierType normalizedServiceGroupId = caseSensitivityNormalizer.normalize(serviceGroupId); + DocumentIdentifier normalizedDocId = caseSensitivityNormalizer.normalize(documentId); + + DBServiceMetadata serviceMetadata = serviceMetadataDao.find(toDbModel(normalizedServiceGroupId, normalizedDocId)); + + if (serviceMetadata == null || serviceMetadata.getXmlContent() == null) { + throw new NotFoundException("ServiceMetadata not found, ServiceGroupID: '%s', DocumentID: '%s'", asString(serviceGroupId), asString(documentId)); + } + + Document aSignedServiceMetadata = toSignedServiceMetadatadaDocument(serviceMetadata.getXmlContent()); + signatureFilter.sign(aSignedServiceMetadata); + return aSignedServiceMetadata; + } + + /** + * Creates or updates ServiceMetadata + * + * @return True if new ServiceMetadata was created. False if existing one was updated. + */ + @Transactional + public boolean saveServiceMetadata(ParticipantIdentifierType serviceGroupId, DocumentIdentifier documentId, String xmlContent) { + ParticipantIdentifierType normalizedServiceGroupId = caseSensitivityNormalizer.normalize(serviceGroupId); + DocumentIdentifier normalizedDocId = caseSensitivityNormalizer.normalize(documentId); + + DBServiceGroup serviceGroup = serviceGroupDao.find(ServiceGroupConverter.toDbModel(normalizedServiceGroupId)); + if (serviceGroup == null) { + throw new NotFoundException("ServiceGroup not found: '%s'", asString(serviceGroupId)); + } + + DBServiceMetadataId dbServiceMetadataId = toDbModel(normalizedServiceGroupId, normalizedDocId); + boolean alreadyExisted = serviceMetadataDao.removeById(dbServiceMetadataId); + + DBServiceMetadata dbServiceMetadata = new DBServiceMetadata(); + dbServiceMetadata.setId(dbServiceMetadataId); + + dbServiceMetadata.setXmlContent(xmlContent); + serviceMetadataDao.save(dbServiceMetadata); + return !alreadyExisted; + } + + @Transactional + public void deleteServiceMetadata(ParticipantIdentifierType serviceGroupId, DocumentIdentifier documentId) { + ParticipantIdentifierType normalizedServiceGroupId = caseSensitivityNormalizer.normalize(serviceGroupId); + DocumentIdentifier normalizedDocId = caseSensitivityNormalizer.normalize(documentId); + + DBServiceMetadataId dbServiceMetadataId = toDbModel(normalizedServiceGroupId, normalizedDocId); + boolean serviceMetadataRemoved = serviceMetadataDao.removeById(dbServiceMetadataId); + + if (!serviceMetadataRemoved) { + throw new NotFoundException("ServiceGroup not found: '%s'", asString(serviceGroupId)); + } + } + + public List<DocumentIdentifier> findServiceMetadataIdentifiers(ParticipantIdentifierType 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.getDocumentIdentifier(), metadataId.getDocumentIdentifierScheme()); + documentIds.add(documentIdentifier); + } + return documentIds; + } +} diff --git a/smp-server-library/src/main/resources/META-INF/smp-persistence.xml b/smp-server-library/src/main/resources/META-INF/smp-persistence.xml deleted file mode 100644 index 35b0083c83d28a99825f568bd02a7358e8d0bb71..0000000000000000000000000000000000000000 --- a/smp-server-library/src/main/resources/META-INF/smp-persistence.xml +++ /dev/null @@ -1,31 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ 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. - --> -<persistence xmlns="http://java.sun.com/xml/ns/persistence" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" - version="2.0"> - <persistence-unit name="peppol-smp" transaction-type="RESOURCE_LOCAL"> - <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> - <class>eu.europa.ec.cipa.smp.server.data.dbms.model.DBEndpoint</class> - <class>eu.europa.ec.cipa.smp.server.data.dbms.model.DBOwnership</class> - <class>eu.europa.ec.cipa.smp.server.data.dbms.model.DBProcess</class> - <class>eu.europa.ec.cipa.smp.server.data.dbms.model.DBServiceGroup</class> - <class>eu.europa.ec.cipa.smp.server.data.dbms.model.DBServiceMetadata</class> - <class>eu.europa.ec.cipa.smp.server.data.dbms.model.DBUser</class> - <class>eu.europa.ec.cipa.smp.server.data.dbms.model.DBServiceMetadataRedirection</class> - <!-- Note: all properties are passed in the code --> - </persistence-unit> -</persistence> diff --git a/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/AbstractTest.java b/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/AbstractTest.java deleted file mode 100644 index 495afd1a0480f1f9fe8b923667732f69575def4c..0000000000000000000000000000000000000000 --- a/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/AbstractTest.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * 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.cipa.smp.server; - -import eu.europa.ec.cipa.smp.server.data.dbms.DBMSDataManager; -import eu.europa.ec.cipa.smp.server.data.dbms.model.*; -import eu.europa.ec.smp.api.Identifiers; -import org.junit.After; -import org.junit.Before; -import org.oasis_open.docs.bdxr.ns.smp._2016._05.ParticipantIdentifierType; - -/** - * Created by rodrfla on 23/01/2017. - */ -public class AbstractTest { - - protected static DBMSDataManager s_aDataMgr = null; - - final static String[][] usernames = new String[][]{{"CN=EHEALTH_SMP_1000000007,O=DG-DIGIT,C=BE:000000000123ABCD", null}, - {"CN=SMP_1000000007,O=DG-DIGIT,C=BE", null}, - {"CN=EHEALTH_SMP_1000000007,O=DG-DIGIT,C=BE", null}, - {"CN=SMP_1000000007,O=DG-DIGIT,C=BE:000000000123ABCD", null}, - {"CN=EHEALTH_SMP_EC/emailAddress\\=CEF-EDELIVERY-SUPPORT@ec.europa.eu,O=European Commission,C=BE:f71ee8b11cb3b787", null}}; -/* - - private static final class SMPTestRule extends ScopeTestRule { - @Override - public void before() { - super.before(); - if (s_aDataMgr == null) { - // Do it only once :) - // SMPEntityManagerFactory.getInstance (); - //s_aDataMgr = DataManagerFactory.getInstance(); - } - } - } -*/ -/* - - @ClassRule - public static TestRule s_aTestRule = new SMPTestRule(); -*/ - - @Before - public void before() throws Throwable { - createDBCertificated(); - createServiceGroup(); - createOwnerShip(); - } - - private static void createServiceGroup() throws Exception { - String serviceGroupId = "ehealth-actorid-qns::urn:australia:ncpb"; - final ParticipantIdentifierType aServiceGroupID = Identifiers.asParticipantId(serviceGroupId); - - final DBServiceGroupID aDBServiceGroupID = new DBServiceGroupID(aServiceGroupID); - DBServiceGroup aDBServiceGroup = s_aDataMgr.getCurrentEntityManager().find(DBServiceGroup.class, aDBServiceGroupID); - if (aDBServiceGroup == null) { - aDBServiceGroup = new DBServiceGroup(aDBServiceGroupID); - s_aDataMgr.getCurrentEntityManager().persist(aDBServiceGroup); - } - } - - private static void createOwnerShip() throws Exception { - String serviceGroupId = "ehealth-actorid-qns::urn:australia:ncpb"; - String username = "CN=EHEALTH_SMP_TEST_BRAZIL/emailAddress\\=CEF-EDELIVERY-SUPPORT@ec.europa.eu,O=European Commission,C=BE:48b681ee8e0dcc08"; - final ParticipantIdentifierType aServiceGroupID = Identifiers.asParticipantId(serviceGroupId); - final DBServiceGroupID aDBServiceGroupID = new DBServiceGroupID(aServiceGroupID); - final DBOwnershipID dbOwnershipID = new DBOwnershipID(username, aServiceGroupID); - DBOwnership dbOwnership = s_aDataMgr.getCurrentEntityManager().find(DBOwnership.class, dbOwnershipID); - if (dbOwnership == null) { - DBUser dbUser = s_aDataMgr.getCurrentEntityManager().find(DBUser.class, username); - if (dbUser != null) { - final DBOwnershipID aDBOwnershipID = new DBOwnershipID(dbUser.getUsername(), aServiceGroupID); - dbOwnership = new DBOwnership(aDBOwnershipID, dbUser, new DBServiceGroup(aDBServiceGroupID)); - s_aDataMgr.getCurrentEntityManager().persist(dbOwnership); - } - } - } - - private static void createDBCertificated() throws Throwable { - for (int i = 0; i < usernames.length; i++) { - DBUser aDBUser = s_aDataMgr.getCurrentEntityManager().find(DBUser.class, usernames[i][0]); - if (aDBUser == null) { - aDBUser = new DBUser(); - aDBUser.setUsername(usernames[i][0]); - aDBUser.setPassword(usernames[i][1]); - s_aDataMgr.getCurrentEntityManager().persist(aDBUser); - } else { - if (aDBUser.getPassword() != null && !aDBUser.getPassword().equals(usernames[i][1])) { - aDBUser.setPassword(usernames[i][1]); - s_aDataMgr.getCurrentEntityManager().merge(aDBUser); - } - } - } - } - - @After - public final void after() throws Throwable { - removeDBUser(); - } - - private static void removeDBUser() throws Throwable { - for (int i = 0; i < usernames.length; i++) { - DBUser aDBUser = s_aDataMgr.getCurrentEntityManager().find(DBUser.class, usernames[i][0]); - if (aDBUser != null) { - s_aDataMgr.getCurrentEntityManager().remove(aDBUser); - } - } - } - -} diff --git a/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/conversion/ServiceGroupConverterTest.java b/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/conversion/ServiceGroupConverterTest.java index 9f43af98d4b0278c49b4a7291605875d5140526a..d3424d4882a5aad2906c515d8f1b49d114e1fc43 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/conversion/ServiceGroupConverterTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/conversion/ServiceGroupConverterTest.java @@ -15,7 +15,7 @@ package eu.europa.ec.cipa.smp.server.conversion; -import eu.europa.ec.cipa.smp.server.errors.exceptions.XmlParsingException; +import eu.europa.ec.edelivery.smp.exceptions.XmlParsingException; import eu.europa.ec.cipa.smp.server.util.XmlTestUtils; import org.junit.Test; import org.oasis_open.docs.bdxr.ns.smp._2016._05.ServiceGroup; diff --git a/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/conversion/ServiceMetadataConverterTest.java b/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/conversion/ServiceMetadataConverterTest.java index d3d4bf09830ad2939012385168dd9a1b0e0473d5..dba89bafdbe9a0d8e5217dd1cb30cdc7055c3154 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/conversion/ServiceMetadataConverterTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/conversion/ServiceMetadataConverterTest.java @@ -15,7 +15,7 @@ package eu.europa.ec.cipa.smp.server.conversion; -import eu.europa.ec.cipa.smp.server.errors.exceptions.XmlParsingException; +import eu.europa.ec.edelivery.smp.exceptions.XmlParsingException; import eu.europa.ec.cipa.smp.server.util.XmlTestUtils; import org.junit.Test; import org.oasis_open.docs.bdxr.ns.smp._2016._05.RedirectType; diff --git a/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/data/dbms/DBMSDataManagerTest.java b/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/data/dbms/DBMSDataManagerTest.java deleted file mode 100644 index 1807cdcf8195b9ea90a642707993cbd425c52ddd..0000000000000000000000000000000000000000 --- a/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/data/dbms/DBMSDataManagerTest.java +++ /dev/null @@ -1,753 +0,0 @@ -/* - * 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.cipa.smp.server.data.dbms; - -import eu.europa.ec.cipa.smp.server.AbstractTest; -import eu.europa.ec.cipa.smp.server.conversion.ServiceMetadataConverter; -import eu.europa.ec.cipa.smp.server.data.dbms.model.*; -import eu.europa.ec.cipa.smp.server.errors.exceptions.NotFoundException; -import eu.europa.ec.cipa.smp.server.errors.exceptions.UnknownUserException; -import eu.europa.ec.cipa.smp.server.security.BCryptPasswordHash; -import eu.europa.ec.cipa.smp.server.util.IdentifierUtils; -import eu.europa.ec.cipa.smp.server.util.SMPDBUtils; -import eu.europa.ec.cipa.smp.server.util.XmlTestUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.oasis_open.docs.bdxr.ns.smp._2016._05.*; -import org.w3c.dom.Element; - -import javax.xml.bind.annotation.XmlRootElement; -import java.util.Arrays; -import java.util.Date; -import java.util.GregorianCalendar; - -import static org.junit.Assert.*; - -/** - * @author PEPPOL.AT, BRZ, Philip Helger - */ -@Ignore -// ("Cannot be enabled by default, because it would fail without the correct configuration") -//@DevelopersNote ("You need to adjust your local config.properties file to run this test") -public class DBMSDataManagerTest extends AbstractTest { - private static final String PARTICIPANT_IDENTIFIER_SCHEME = CommonColumnsLengths.DEFAULT_PARTICIPANT_IDENTIFIER_SCHEME; - private static final String DOCUMENT_SCHEME = CommonColumnsLengths.DEFAULT_DOCUMENT_TYPE_IDENTIFIER_SCHEME; - private static final String PROCESS_SCHEME = CommonColumnsLengths.DEFAULT_PROCESS_IDENTIFIER_SCHEME; - - private static final String PARTICIPANT_IDENTIFIER1 = "0010:599900000000A"; - private static final String PARTICIPANT_IDENTIFIER2 = "0010:599900000000B"; - - private static final String TEST_DOCTYPE_ID = "doc1"; - private static final String TEST_PROCESS_ID = "bis4"; - - private static final String USERNAME = "peppol_user"; - private static final String PASSWORD = "Test1234"; - private static final String ADMIN_USERNAME = "the_admin"; - private static final String NOADMIN_USERNAME = "CN=SMP_1000000181,O=DIGIT,C=DK:123456789"; - private static final String NOADMIN_PASSWORD = "123456789"; - private static final String NOADMIN_PASSWORD_HASH = BCryptPasswordHash.hashPassword(NOADMIN_PASSWORD); - - - //public static final BasicAuthClientCredentials ADMIN_CREDENTIALS = new BasicAuthClientCredentials(ADMIN_USERNAME, null); - public static final String ADMIN_CREDENTIALS = ADMIN_USERNAME; - - private static final String CERTIFICATE = "VGhpcyBpcyBzdXJlbHkgbm90IGEgdmFsaWQgY2VydGlmaWNhdGUsIGJ1dCBpdCBo\n" - + "YXMgbW9yZSB0aGFuIDY0IGNoYXJhY3RlcnM="; - private static final String ADDRESS = "http://test.eu/accesspoint.svc"; - private static final boolean REQUIRE_SIGNATURE = true; - private static final String MINIMUM_AUTH_LEVEL = "1"; - private static final Date ACTIVATION_DATE = GregorianCalendar.getInstance().getTime(); - private static final String DESCRIPTION = "description123"; - private static final String DESCRIPTION_2 = "new description"; - private static final Date EXPIRATION_DATE = GregorianCalendar.getInstance().getTime(); - private static final String TECH_CONTACT = "fake@peppol.eu"; - private static final String TECH_INFO = "http://fake.peppol.eu/"; - private static final String TRANSPORT_PROFILE = "bdxr-transport-ebms3-as4"; - - private static final ParticipantIdentifierType PARTY_ID = new ParticipantIdentifierType(PARTICIPANT_IDENTIFIER1,"iso6523-actorid-upis"); - private static final ParticipantIdentifierType SERVICEGROUP_ID = PARTY_ID; - private static final DocumentIdentifier DOCTYPE_ID = new DocumentIdentifier(TEST_DOCTYPE_ID, DOCUMENT_SCHEME); - - //private static final BasicAuthClientCredentials CREDENTIALS = new BasicAuthClientCredentials (USERNAME, PASSWORD); - private static final String CREDENTIALS = USERNAME; - - private ServiceGroup m_aServiceGroup; - private ServiceMetadata m_aServiceMetadata; - private String m_sServiceMetadata; - private boolean isServiceGroupToDelete = false; - private boolean isServiceMetadataToDelete = false; - - @Before - public void beforeTest () throws Throwable { - createOrUpdatedDBUser(NOADMIN_USERNAME, NOADMIN_PASSWORD_HASH, false); - createOrUpdatedDBUser(ADMIN_USERNAME, null, true); - - //SMPDBUtils.getAsExtensionSafe("<root><any>value</any></root>"); - final ExtensionType aExtension = new ExtensionType(); - - assertNotNull (aExtension); - assertNotNull (aExtension.getAny ()); - - final ObjectFactory aObjFactory = new ObjectFactory (); - m_aServiceGroup = aObjFactory.createServiceGroup (); - m_aServiceGroup.setParticipantIdentifier (PARTY_ID); - - // Be sure to delete if it exists. - try { - s_aDataMgr.deleteServiceGroup (SERVICEGROUP_ID); - } - catch (final Exception ex) {} - - // Create a new one - s_aDataMgr.saveServiceGroup (m_aServiceGroup, CREDENTIALS); - - m_aServiceMetadata = aObjFactory.createServiceMetadata (); - final ServiceInformationType aServiceInformation = aObjFactory.createServiceInformationType (); - aServiceInformation.setDocumentIdentifier (DOCTYPE_ID); - aServiceInformation.setParticipantIdentifier (PARTY_ID); - aServiceInformation.getExtensions().add(aExtension); - { - final ProcessListType processList = aObjFactory.createProcessListType (); - { - final ProcessType process = aObjFactory.createProcessType (); - process.setProcessIdentifier (new ProcessIdentifier(TEST_PROCESS_ID, PROCESS_SCHEME)); - process.getExtensions().add(aExtension); - { - final ServiceEndpointList serviceEndpointList = aObjFactory.createServiceEndpointList (); - { - final EndpointType endpoint = aObjFactory.createEndpointType (); - endpoint.setCertificate (CERTIFICATE.getBytes()); - endpoint.setEndpointURI(ADDRESS); - endpoint.setMinimumAuthenticationLevel (MINIMUM_AUTH_LEVEL); - endpoint.setRequireBusinessLevelSignature (REQUIRE_SIGNATURE); - endpoint.setServiceActivationDate (ACTIVATION_DATE); - endpoint.setServiceDescription (DESCRIPTION); - endpoint.setServiceExpirationDate (EXPIRATION_DATE); - endpoint.getExtensions().add(aExtension); - endpoint.setTechnicalContactUrl (TECH_CONTACT); - endpoint.setTechnicalInformationUrl (TECH_INFO); - endpoint.setTransportProfile (TRANSPORT_PROFILE); - serviceEndpointList.getEndpoints().add (endpoint); - } - process.setServiceEndpointList (serviceEndpointList); - } - processList.getProcesses().add (process); - } - aServiceInformation.setProcessList (processList); - } - m_aServiceMetadata.setServiceInformation (aServiceInformation); - m_sServiceMetadata = XmlTestUtils.marshall(m_aServiceMetadata); - } - - private final void createOrUpdatedDBUser(String username, String password, boolean isAdmin) throws Throwable { - DBUser aDBUser = s_aDataMgr.getCurrentEntityManager().find(DBUser.class, username); - - if(aDBUser == null){ - aDBUser = new DBUser(); - aDBUser.setUsername(username); - aDBUser.setPassword(password); - aDBUser.setAdmin(isAdmin); - s_aDataMgr.getCurrentEntityManager().persist(aDBUser); - }else{ - aDBUser.setPassword(password); - aDBUser.setAdmin(isAdmin); - s_aDataMgr.getCurrentEntityManager().merge(aDBUser); - } - } - - @Test - public void testCreateServiceGroup () throws Throwable { - m_aServiceGroup.getParticipantIdentifier ().setValue (PARTICIPANT_IDENTIFIER2); - - s_aDataMgr.deleteServiceGroup(PARTY_ID); - - boolean bNewServiceGroupCreated = s_aDataMgr.saveServiceGroup (m_aServiceGroup, CREDENTIALS); - - final ParticipantIdentifierType aParticipantIdentifier2 = new ParticipantIdentifierType(PARTICIPANT_IDENTIFIER2, "iso6523-actorid-upis"); - final ServiceGroup result = s_aDataMgr.getServiceGroup (aParticipantIdentifier2); - assertTrue(bNewServiceGroupCreated); - assertNotNull (result); - - assertNull (result.getServiceMetadataReferenceCollection ()); - assertEquals (PARTICIPANT_IDENTIFIER_SCHEME, result.getParticipantIdentifier ().getScheme ()); - assertTrue (IdentifierUtils.areParticipantIdentifierValuesEqual (PARTICIPANT_IDENTIFIER2, - result.getParticipantIdentifier ().getValue ())); - } - - @Test - public void testUpdateServiceByAdmin () throws Throwable { - //given - s_aDataMgr.deleteServiceGroup(PARTY_ID); - - ServiceGroup sg = new ServiceGroup(); - sg.setParticipantIdentifier(PARTY_ID); - boolean bNewServiceGroupCreated = s_aDataMgr.saveServiceGroup (m_aServiceGroup, CREDENTIALS); - ServiceGroup serviceGroup = s_aDataMgr.getServiceGroup(PARTY_ID); - assertNotNull(serviceGroup.getExtensions()); - assertEquals(0,serviceGroup.getExtensions().size()); - - //when - ExtensionType extension = new ExtensionType(); - extension.setExtensionID("the id"); - sg.getExtensions().add(0, extension); - boolean bNewServiceGroupUpdated = s_aDataMgr.saveServiceGroup(sg, ADMIN_CREDENTIALS); - - //then - assertTrue(bNewServiceGroupCreated); - assertFalse(bNewServiceGroupUpdated); - ServiceGroup newGroup = s_aDataMgr.getServiceGroup(PARTY_ID); - assertEquals(1, newGroup.getExtensions().size()); - assertEquals("the id", newGroup.getExtensions().get(0).getExtensionID()); - } - - @Test - public void testDeleteServiceGroupByAdmin () throws Throwable { - //given - ServiceGroup sg = new ServiceGroup(); - sg.setParticipantIdentifier(PARTY_ID); - s_aDataMgr.saveServiceGroup (m_aServiceGroup, CREDENTIALS); - - //when - s_aDataMgr.deleteServiceGroup(PARTY_ID); - - //then - assertNull(s_aDataMgr.getServiceGroup(PARTY_ID)); - } - - /* Password verified by spring-security - - @Test - public void testCreateServiceGroupInvalidPassword () throws Throwable { - final BasicAuthClientCredentials aCredentials = new BasicAuthClientCredentials (USERNAME, "WRONG_PASSWORD"); - - m_aServiceGroup.getParticipantIdentifier ().setValue (PARTICIPANT_IDENTIFIER2); - try { - s_aDataMgr.saveServiceGroup (m_aServiceGroup, aCredentials); - fail (); - } - catch (final UnauthorizedException ex) {} - } - */ - - @Test - public void testCreateServiceGroupUnknownUser () throws Throwable { - //final BasicAuthClientCredentials aCredentials = new BasicAuthClientCredentials ("Unknown_User", PASSWORD); - - m_aServiceGroup.getParticipantIdentifier ().setValue (PARTICIPANT_IDENTIFIER2); - try { - s_aDataMgr.saveServiceGroup (m_aServiceGroup, "Unknown_User"); - fail (); - } - catch (final UnknownUserException ex) {} - } - - @Test - public void testDeleteServiceGroup () throws Throwable { - s_aDataMgr.deleteServiceGroup (SERVICEGROUP_ID); - assertNull (s_aDataMgr.getServiceGroup (SERVICEGROUP_ID)); - } - - @Test - public void testDeleteServiceGroupUnknownID () throws Throwable { - final ParticipantIdentifierType aServiceGroupID2 = new ParticipantIdentifierType(PARTICIPANT_IDENTIFIER2, "iso6523-actorid-upis"); - try { - s_aDataMgr.deleteServiceGroup (aServiceGroupID2); - } - catch (final NotFoundException ex) {} - assertNull (s_aDataMgr.getServiceGroup (aServiceGroupID2)); - } - - @Test - public void testDeleteServiceGroupUnknownUser () throws Throwable { - //final BasicAuthClientCredentials aCredentials = new BasicAuthClientCredentials ("Unknown_User", PASSWORD); - try { - s_aDataMgr.deleteServiceGroup (SERVICEGROUP_ID); - s_aDataMgr.getCurrentEntityManager().getTransaction().commit(); - fail (); - } - catch (final UnknownUserException ex) {} - } - - /* Password verified by Spring-security - @Test - public void testDeleteServiceGroupWrongPass () throws Throwable { - final BasicAuthClientCredentials aCredentials = new BasicAuthClientCredentials (USERNAME, "WrongPassword"); - try { - s_aDataMgr.deleteServiceGroup (SERVICEGROUP_ID, aCredentials); - fail (); - } - catch (final UnauthorizedException ex) {} - } - */ - - @Test - public void testCreateServiceMetadata() throws Throwable { - // Save to DB - boolean bNewServiceMetadataCreated = s_aDataMgr.saveService(SERVICEGROUP_ID, DOCTYPE_ID, m_sServiceMetadata); - - // Retrieve from DB - final String docDBServiceMetadata = s_aDataMgr.getService (SERVICEGROUP_ID, DOCTYPE_ID); - final ServiceMetadata aDBServiceMetadata = ServiceMetadataConverter.unmarshal(docDBServiceMetadata); - assertNotNull (aDBServiceMetadata); - - final ProcessListType aOrigProcessList = m_aServiceMetadata.getServiceInformation ().getProcessList (); - assertEquals (1, aOrigProcessList.getProcesses().size ()); - final ProcessType aOrigProcess = aOrigProcessList.getProcesses().get (0); - assertEquals (1, aOrigProcess.getServiceEndpointList ().getEndpoints().size ()); - final EndpointType aOrigEndpoint = aOrigProcess.getServiceEndpointList ().getEndpoints().get (0); - - final ProcessType aDBProcess = aDBServiceMetadata.getServiceInformation ().getProcessList ().getProcesses().get (0); - final EndpointType aDBEndpoint = aDBProcess.getServiceEndpointList ().getEndpoints().get (0); - - assertTrue(bNewServiceMetadataCreated); - assertTrue (IdentifierUtils.areIdentifiersEqual (m_aServiceMetadata.getServiceInformation () - .getDocumentIdentifier (), - aDBServiceMetadata.getServiceInformation () - .getDocumentIdentifier ())); - assertTrue (IdentifierUtils.areIdentifiersEqual (m_aServiceMetadata.getServiceInformation () - .getParticipantIdentifier (), - aDBServiceMetadata.getServiceInformation () - .getParticipantIdentifier ())); - assertTrue (IdentifierUtils.areIdentifiersEqual (aOrigProcess.getProcessIdentifier (), - aDBProcess.getProcessIdentifier ())); - assertArrayEquals (aOrigEndpoint.getCertificate (), aDBEndpoint.getCertificate ()); - assertEquals (aOrigEndpoint.getMinimumAuthenticationLevel (), aDBEndpoint.getMinimumAuthenticationLevel ()); - assertEquals (aOrigEndpoint.getServiceDescription (), aDBEndpoint.getServiceDescription ()); - assertEquals (aOrigEndpoint.getTechnicalContactUrl (), aDBEndpoint.getTechnicalContactUrl ()); - assertEquals (aOrigEndpoint.getTechnicalInformationUrl (), aDBEndpoint.getTechnicalInformationUrl ()); - assertEquals (aOrigEndpoint.getTransportProfile (), aDBEndpoint.getTransportProfile ()); - assertEquals (aOrigEndpoint.getEndpointURI(), aDBEndpoint.getEndpointURI()); - - isServiceMetadataToDelete = true; - } - - @Test - public void testServiceMetadataCaseInSensitivity() throws Throwable { - //given - String inParticipantValue = PARTICIPANT_IDENTIFIER1+"ABCxyz"; - String inParticipantScheme = "participant-SCHEME-with-lower-and-UPPER"; - String inDocValue = TEST_DOCTYPE_ID+"ABCxyz"; - String inDocScheme = "document-SCHEME-with-lower-and-UPPER"; - ParticipantIdentifierType inParticipantId = new ParticipantIdentifierType(inParticipantValue, inParticipantScheme); - DocumentIdentifier inDocId = new DocumentIdentifier(inDocValue, inDocScheme); - ParticipantIdentifierType inParticipantIdUpper = new ParticipantIdentifierType(inParticipantValue.toUpperCase(), inParticipantScheme.toUpperCase()); - DocumentIdentifier inDocIdUpper = new DocumentIdentifier(inDocValue.toUpperCase(), inDocScheme.toUpperCase()); - m_aServiceMetadata.getServiceInformation().setParticipantIdentifier(inParticipantId); - m_aServiceMetadata.getServiceInformation().setDocumentIdentifier(inDocId); - m_sServiceMetadata = XmlTestUtils.marshall(m_aServiceMetadata); - - m_aServiceGroup = createServiceGroup(inParticipantValue, inParticipantScheme); - s_aDataMgr.saveServiceGroup(m_aServiceGroup, CREDENTIALS); - - //when - s_aDataMgr.saveService(inParticipantId, inDocId, m_sServiceMetadata /*, CREDENTIALS*/); - - //then - String resultServiceMetadataStr = s_aDataMgr.getService (inParticipantId, inDocId); - String resultServiceMetadataStrFromUpperCaseId = s_aDataMgr.getService (inParticipantIdUpper, inDocIdUpper); - - assertEquals(resultServiceMetadataStr, resultServiceMetadataStrFromUpperCaseId); - ServiceMetadata resultServiceMetadata = ServiceMetadataConverter.unmarshal(resultServiceMetadataStr); - ParticipantIdentifierType resultParticipantId = resultServiceMetadata.getServiceInformation().getParticipantIdentifier(); - DocumentIdentifier resultDocId = resultServiceMetadata.getServiceInformation().getDocumentIdentifier(); - - assertEquals(inParticipantValue, resultParticipantId.getValue()); - assertEquals(inParticipantScheme, resultParticipantId.getScheme()); - assertEquals(inDocValue, resultDocId.getValue()); - assertEquals(inDocScheme, resultDocId.getScheme()); - - //when - s_aDataMgr.deleteService(inParticipantId, inDocId /*, CREDENTIALS*/); - - //then - resultServiceMetadataStr = s_aDataMgr.getService (inParticipantId, inDocId); - assertNull(resultServiceMetadataStr); - } - - @Test(expected = NotFoundException.class) - public void testCreateServiceMetadataNonExistingServiceGroup() throws Throwable { - final ParticipantIdentifierType serviceGroupNonExisting = new ParticipantIdentifierType("nonexisting","iso6523-actorid-upis"); - s_aDataMgr.saveService(serviceGroupNonExisting, DOCTYPE_ID, m_sServiceMetadata /*, CREDENTIALS*/); - } - - @Test(expected = NotFoundException.class) - public void testCreateServiceMetadataByAdminNonExistingServiceGroup() throws Throwable { - final ParticipantIdentifierType serviceGroupNonExisting = new ParticipantIdentifierType("nonexisting","iso6523-actorid-upis"); - s_aDataMgr.saveService(serviceGroupNonExisting, DOCTYPE_ID, m_sServiceMetadata /*, ADMIN_CREDENTIALS*/ ); - } - - @Test(expected = NotFoundException.class) - public void testCreateServiceMetadataByNoAdminNonExistingServiceGroup() throws Throwable { - final ParticipantIdentifierType serviceGroupNonExisting = new ParticipantIdentifierType("nonexisting","iso6523-actorid-upis"); - //final BasicAuthClientCredentials noAdminCredentials = new BasicAuthClientCredentials (NOADMIN_USERNAME, NOADMIN_PASSWORD); - s_aDataMgr.saveService(serviceGroupNonExisting, DOCTYPE_ID, m_sServiceMetadata /*, NOADMIN_USERNAME*/); - } - - @Test - public void testCreateServiceMetadataRedirect() throws Throwable { - final String PARTICIPANT_IDENTIFIER3 = "0010:599900000000C"; - final ParticipantIdentifierType PARTY_ID3 = new ParticipantIdentifierType(PARTICIPANT_IDENTIFIER3,"iso6523-actorid-upis"); - final ObjectFactory aObjFactory = new ObjectFactory (); - m_aServiceGroup = aObjFactory.createServiceGroup (); - m_aServiceGroup.setParticipantIdentifier (PARTY_ID3); - - // Be sure to delete if it exists. - try { - s_aDataMgr.deleteServiceGroup (PARTY_ID3); - } - catch (final Exception ex) {} - - // Create a new one - s_aDataMgr.saveServiceGroup (m_aServiceGroup, CREDENTIALS); - - ServiceMetadata m_aServiceMetadataRedirect = aObjFactory.createServiceMetadata(); - RedirectType redirect = aObjFactory.createRedirectType(); - redirect.setCertificateUID("certificateUID"); - redirect.setHref("href"); - - ExtensionType extension = aObjFactory.createExtensionType(); - extension.setExtensionAgencyID("agencyId"); - extension.setExtensionAgencyName("agencyName"); - extension.setExtensionAgencyURI("uri"); - extension.setExtensionID("id"); - extension.setExtensionName("name"); - extension.setExtensionReason("reason"); - extension.setExtensionReasonCode("reasonCode"); - extension.setExtensionVersionID("versionId"); - - redirect.getExtensions().add(extension); - m_aServiceMetadataRedirect.setRedirect(redirect); - - String m_sServiceMetadataRedirect = XmlTestUtils.marshall(m_aServiceMetadataRedirect); - - // Save to DB - boolean bNewServiceMetadataCreated = s_aDataMgr.saveService(PARTY_ID3, DOCTYPE_ID, m_sServiceMetadataRedirect /*, CREDENTIALS*/); - - // Retrieve from DB - assertTrue(bNewServiceMetadataCreated); - final String docDBServiceMetadata = s_aDataMgr.getService (PARTY_ID3, DOCTYPE_ID); - final ServiceMetadata aDBServiceMetadata = ServiceMetadataConverter.unmarshal(docDBServiceMetadata); - assertNotNull (aDBServiceMetadata); - - RedirectType redirectDB = aDBServiceMetadata.getRedirect(); - assertNotNull(redirectDB); - assertEquals(redirect.getHref(), redirectDB.getHref()); - assertEquals(redirect.getCertificateUID(), redirectDB.getCertificateUID()); - ExtensionType extensionDB = redirectDB.getExtensions().get(0); - assertNotNull(extensionDB); - assertEquals(extension.getExtensionAgencyID(), extensionDB.getExtensionAgencyID()); - assertEquals(extension.getExtensionAgencyName(), extensionDB.getExtensionAgencyName()); - assertEquals(extension.getExtensionAgencyURI(), extensionDB.getExtensionAgencyURI()); - assertEquals(extension.getExtensionID(), extensionDB.getExtensionID()); - assertEquals(extension.getExtensionName(), extensionDB.getExtensionName()); - assertEquals(extension.getExtensionReason(), extensionDB.getExtensionReason()); - assertEquals(extension.getExtensionReasonCode(), extensionDB.getExtensionReasonCode()); - assertEquals(extension.getExtensionVersionID(), extensionDB.getExtensionVersionID()); - } - - @Test - public void testUpdateServiceMetadataByAdmin() throws Throwable { - // given - boolean bNewServiceMetadataCreated = s_aDataMgr.saveService(PARTY_ID, DOCTYPE_ID, m_sServiceMetadata /*, CREDENTIALS*/); - String strMetadata = s_aDataMgr.getService(PARTY_ID, DOCTYPE_ID); - ServiceMetadata metadata = ServiceMetadataConverter.unmarshal(strMetadata); - EndpointType endpoint = metadata.getServiceInformation().getProcessList().getProcesses().get(0).getServiceEndpointList().getEndpoints().get(0); - assertEquals(DESCRIPTION, endpoint.getServiceDescription()); - - //when - m_sServiceMetadata = m_sServiceMetadata.replaceAll(DESCRIPTION, DESCRIPTION_2); - boolean bNewServiceMetadataUpdated = s_aDataMgr.saveService(PARTY_ID, DOCTYPE_ID, m_sServiceMetadata/*, ADMIN_CREDENTIALS*/ ); - - //then - assertTrue(bNewServiceMetadataCreated); - assertFalse(bNewServiceMetadataUpdated); - String strNewMetadata = s_aDataMgr.getService(PARTY_ID, DOCTYPE_ID); - ServiceMetadata newMetadata = ServiceMetadataConverter.unmarshal(strNewMetadata); - EndpointType newEndpoint = newMetadata.getServiceInformation().getProcessList().getProcesses().get(0).getServiceEndpointList().getEndpoints().get(0); - assertEquals(DESCRIPTION_2, newEndpoint.getServiceDescription()); - } - - @Test - public void testDeleteServiceMetadataByAdmin() throws Throwable { - // given - boolean bNewServiceMetadataCreated = s_aDataMgr.saveService(PARTY_ID, DOCTYPE_ID, m_sServiceMetadata /*, CREDENTIALS*/); - - //when - s_aDataMgr.deleteService(PARTY_ID, DOCTYPE_ID/*, ADMIN_CREDENTIALS*/ ); - - //then - assertTrue(bNewServiceMetadataCreated); - assertNull(s_aDataMgr.getService(PARTY_ID, DOCTYPE_ID)); - } - - @Test - public void testCreateServiceMetadataUnknownUser() throws Throwable { - //final BasicAuthClientCredentials aCredentials = new BasicAuthClientCredentials ("Unknown_User", PASSWORD); - try { - s_aDataMgr.saveService(PARTY_ID, DOCTYPE_ID, m_sServiceMetadata /*, "Unknown_User"*/); - fail (); - } - catch (final UnknownUserException ex) {} - } - - - - @Test - public void testPrintServiceMetadata() throws Throwable { - // Ensure something is present :) - isServiceMetadataToDelete = true; - s_aDataMgr.saveService(SERVICEGROUP_ID, DOCTYPE_ID, m_sServiceMetadata /*, CREDENTIALS*/); - System.out.println (s_aDataMgr.getService (SERVICEGROUP_ID, DOCTYPE_ID)); - } - - @Test - public void testDeleteServiceMetadata() throws Throwable { - // Ensure something is present :) - s_aDataMgr.saveService(SERVICEGROUP_ID, DOCTYPE_ID, m_sServiceMetadata /*, CREDENTIALS*/); - - // First deletion succeeds - s_aDataMgr.deleteService (SERVICEGROUP_ID, DOCTYPE_ID /*, CREDENTIALS*/); - try { - // Second deletion fails - s_aDataMgr.deleteService (SERVICEGROUP_ID, DOCTYPE_ID /*, CREDENTIALS*/); - fail (); - } - catch (final NotFoundException ex) {} - } - - @Test - public void testDeleteServiceMetadataUnknownUser () throws Throwable { - //final BasicAuthClientCredentials aCredentials = new BasicAuthClientCredentials ("Unknown_User", PASSWORD); - try { - s_aDataMgr.deleteService (SERVICEGROUP_ID, DOCTYPE_ID /*, "Unknown_User"*/); - fail (); - } - catch (final UnknownUserException ex) {} - } - - - - - @Test(expected = NotFoundException.class) - public void testDeleteServiceMetadataNonExistingServiceGroup() throws Throwable { - final ParticipantIdentifierType serviceGroupNonExisting = new ParticipantIdentifierType("nonexisting","iso6523-actorid-upis"); - s_aDataMgr.deleteService(serviceGroupNonExisting, DOCTYPE_ID /*, CREDENTIALS*/); - } - - @Test(expected = NotFoundException.class) - public void testDeleteServiceMetadataByAdminNonExistingServiceGroup() throws Throwable { - final ParticipantIdentifierType serviceGroupNonExisting = new ParticipantIdentifierType("nonexisting","iso6523-actorid-upis"); - s_aDataMgr.deleteService(serviceGroupNonExisting, DOCTYPE_ID/*, ADMIN_CREDENTIALS*/ ); - } - - @Test(expected = NotFoundException.class) - public void testDeleteServiceMetadataByNoAdminNonExistingServiceGroup() throws Throwable { - final ParticipantIdentifierType serviceGroupNonExisting = new ParticipantIdentifierType("nonexisting","iso6523-actorid-upis"); - //final BasicAuthClientCredentials noAdminCredentials = new BasicAuthClientCredentials (NOADMIN_USERNAME, NOADMIN_PASSWORD); - s_aDataMgr.deleteService(serviceGroupNonExisting, DOCTYPE_ID /*, NOADMIN_USERNAME*/); - } - - @Test - public void testSaveServiceGroup() throws Throwable { - // # Authentication # - //BasicAuthClientCredentials auth =CREDENTIALS; - - // # Delete after leaving test # - isServiceGroupToDelete = true; - - // # Save ServiceGroup # - String participantId = PARTICIPANT_IDENTIFIER2 + "654987"; - m_aServiceGroup = createServiceGroup(participantId); - ParticipantIdentifierType participantIdedntifierLowerCase = new ParticipantIdentifierType(m_aServiceGroup.getParticipantIdentifier().getValue().toLowerCase(), m_aServiceGroup.getParticipantIdentifier().getScheme().toLowerCase()); - s_aDataMgr.deleteServiceGroup(PARTY_ID); - - //when - boolean bNewServiceGroupCreated = s_aDataMgr.saveServiceGroup(m_aServiceGroup, CREDENTIALS); - - //then - ServiceGroup result = s_aDataMgr.getServiceGroup(m_aServiceGroup.getParticipantIdentifier()); - - // # Check ServiceGroup after save # - assertNotNull(result); - assertNull(result.getServiceMetadataReferenceCollection()); - assertEquals(PARTICIPANT_IDENTIFIER_SCHEME, result.getParticipantIdentifier().getScheme()); - assertTrue(IdentifierUtils.areParticipantIdentifierValuesEqual(participantId, - result.getParticipantIdentifier().getValue())); - // # Check Ownership # - assertNotNull( s_aDataMgr.getCurrentEntityManager().find(DBOwnership.class, new DBOwnershipID(USERNAME, participantIdedntifierLowerCase))); - assertTrue(bNewServiceGroupCreated); - - //Sorry for that - but this tests are so bad that one interact with each other ... started failing after fixed one issue - s_aDataMgr.deleteServiceGroup(m_aServiceGroup.getParticipantIdentifier()); - } - - @Test - public void testServiceGroupCaseSensitivity() throws Throwable { - //given - String participantId = PARTICIPANT_IDENTIFIER2 + "ABC"; - String participantScheme = "case-SENSITIVE-participant-2"; - m_aServiceGroup = createServiceGroup(participantId, participantScheme); - ParticipantIdentifierType participantIdentifier = m_aServiceGroup.getParticipantIdentifier(); - ParticipantIdentifierType participantIdentifierUpper = new ParticipantIdentifierType(participantId.toUpperCase(), participantScheme.toUpperCase()); - - //when - s_aDataMgr.saveServiceGroup(m_aServiceGroup, CREDENTIALS); - - //then - ServiceGroup result = s_aDataMgr.getServiceGroup(participantIdentifierUpper); - assertNull(result); - - result = s_aDataMgr.getServiceGroup(participantIdentifier); - assertEquals(participantIdentifier.getValue(),result.getParticipantIdentifier().getValue()); - assertEquals(participantIdentifier.getScheme(),result.getParticipantIdentifier().getScheme()); - - //when - s_aDataMgr.deleteServiceGroup(participantIdentifier); - - //then - result = s_aDataMgr.getServiceGroup(participantIdentifier); - assertNull(result); - } - - @Test - public void testServiceGroupCaseInsensitivity() throws Throwable { - //given - String participantId = PARTICIPANT_IDENTIFIER2 + "ABC"; - m_aServiceGroup = createServiceGroup(participantId); - ParticipantIdentifierType inputParticipantId = m_aServiceGroup.getParticipantIdentifier(); - - //when - s_aDataMgr.saveServiceGroup(m_aServiceGroup, CREDENTIALS); - - //then - ServiceGroup result = s_aDataMgr.getServiceGroup(inputParticipantId); - assertNotNull(result); - assertNotEquals(inputParticipantId.getValue(), result.getParticipantIdentifier().getValue()); - assertEquals(inputParticipantId.getValue().toLowerCase(),result.getParticipantIdentifier().getValue()); - - //when - s_aDataMgr.deleteServiceGroup(inputParticipantId); - - //then - result = s_aDataMgr.getServiceGroup(inputParticipantId); - assertNull(result); - } - - - - @Test(expected = UnknownUserException.class) - public void testSaveServiceGroupByCertificateNotFound() throws Throwable { - String certificateIdentifierHeader = "CN=SMP_123456789,O=DIGIT,C=PT:123456789"; - - ServiceGroup serviceGroup = createServiceGroup(certificateIdentifierHeader); - //BasicAuthClientCredentials auth = new BasicAuthClientCredentials(certificateIdentifierHeader, "100password"); - s_aDataMgr.saveServiceGroup(serviceGroup, certificateIdentifierHeader); - } - - @Test(expected = UnknownUserException.class) - public void testSaveServiceGroupByUserNotFound() throws Throwable { - String participantId = PARTICIPANT_IDENTIFIER2 + "123456789"; - ServiceGroup serviceGroup = createServiceGroup(participantId); - - //BasicAuthClientCredentials auth = new BasicAuthClientCredentials ("123456789", PASSWORD); - s_aDataMgr.saveServiceGroup(serviceGroup, "123456789"); - } - - @Test - public void verifyUser() throws Throwable { - //BasicAuthClientCredentials auth = CREDENTIALS; - DBUser user = s_aDataMgr._verifyUser(CREDENTIALS); - assertNotNull(user); - assertNotNull(user.getUsername(),CREDENTIALS); - assertNotNull(user.getPassword(),CREDENTIALS); - } - - - - - - @Test - public void verifyUserNullAllowed() throws Throwable { - // # Look for user - DBUser aDBUser = s_aDataMgr.getCurrentEntityManager().find(DBUser.class, CREDENTIALS); - assertNotNull(aDBUser); - - // # Set password to null and save - aDBUser.setPassword(null); - s_aDataMgr.getCurrentEntityManager().merge(aDBUser); - - // # Check if password is null - aDBUser = s_aDataMgr.getCurrentEntityManager().find(DBUser.class, CREDENTIALS); - assertNull(aDBUser.getPassword()); - - // # Validate authentication with null password in the request and database - //BasicAuthClientCredentials auth = new BasicAuthClientCredentials(CREDENTIALS.getUserName(),null); - DBUser user = s_aDataMgr._verifyUser(CREDENTIALS); - assertNotNull(user); - - aDBUser.setPassword(PASSWORD); - s_aDataMgr.getCurrentEntityManager().merge(aDBUser); - } - - private ServiceGroup createServiceGroup(String participantId) { - final ObjectFactory aObjFactory = new ObjectFactory(); - ServiceGroup m_aServiceGroup = aObjFactory.createServiceGroup(); - ParticipantIdentifierType participant = new ParticipantIdentifierType(participantId, PARTY_ID.getScheme()); - m_aServiceGroup.setParticipantIdentifier(participant); - return m_aServiceGroup; - } - - private ServiceGroup createServiceGroup(String participantId, String participantScheme) { - ServiceGroup serviceGroup = createServiceGroup(participantId); - ParticipantIdentifierType participant = new ParticipantIdentifierType(participantId, participantScheme); - serviceGroup.setParticipantIdentifier(participant); - return serviceGroup; - } - - @After - public void deleteServiceGroup() throws Throwable { - if (isServiceGroupToDelete) { - DBServiceGroup aDBServiceGroup = s_aDataMgr.getCurrentEntityManager().find(DBServiceGroup.class, new DBServiceGroupID(m_aServiceGroup.getParticipantIdentifier())); - if (aDBServiceGroup != null) { - s_aDataMgr.getCurrentEntityManager().remove(aDBServiceGroup); - isServiceGroupToDelete = false; - } - } - } - - @After - public void deleteServiceMetadata() throws Throwable { - if (isServiceMetadataToDelete) { - DBServiceMetadata serviceMetadata = s_aDataMgr.getCurrentEntityManager().find(DBServiceMetadata.class, new DBServiceMetadataID(SERVICEGROUP_ID, DOCTYPE_ID)); - if (serviceMetadata != null) { - s_aDataMgr.getCurrentEntityManager().remove(serviceMetadata); - isServiceMetadataToDelete = false; - } - } - } - - @After - public void deleteUser() throws Throwable { - String[] usernames = new String[]{PARTICIPANT_IDENTIFIER2 + "654987",NOADMIN_USERNAME, ADMIN_USERNAME}; - for(String username : Arrays.asList(usernames)){ - DBUser aDBUser = s_aDataMgr.getCurrentEntityManager().find(DBUser.class, username); - if(aDBUser != null) { - s_aDataMgr.getCurrentEntityManager().remove(aDBUser); - } - } - } -} \ No newline at end of file diff --git a/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/errors/exceptions/UnknownUserExceptionTest.java b/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/errors/exceptions/UnknownUserExceptionTest.java deleted file mode 100644 index d80e39490b3174c64654c48abacd80f6d91982ea..0000000000000000000000000000000000000000 --- a/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/errors/exceptions/UnknownUserExceptionTest.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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.cipa.smp.server.errors.exceptions; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -/** - * Created by migueti on 16/01/2017. - */ -public class UnknownUserExceptionTest { - - @Test - public void testUnknownUserExceptionThrown() { - // given - - // when - try { - thrownUnknownUserException(); - } catch(UnknownUserException ex) { - // then - assertEquals("unknown_user", ex.getUserName()); - assertEquals("Unknown user 'unknown_user'", ex.getMessage()); - return; - } - fail(); - } - - private void thrownUnknownUserException() { - throw new UnknownUserException("unknown_user"); - } -} diff --git a/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/services/BaseServiceGroupInterfaceImplTest.java b/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/services/BaseServiceGroupInterfaceImplTest.java deleted file mode 100644 index 486fc64d5798cd19e001960510a6e72837a5cdb8..0000000000000000000000000000000000000000 --- a/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/services/BaseServiceGroupInterfaceImplTest.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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.cipa.smp.server.services; - -import eu.europa.ec.cipa.smp.server.conversion.ServiceGroupConverter; -import eu.europa.ec.cipa.smp.server.data.dbms.DBMSDataManager; -import eu.europa.ec.cipa.smp.server.util.XmlTestUtils; -import eu.europa.ec.edelivery.smp.config.SmpServicesTestConfig; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.oasis_open.docs.bdxr.ns.smp._2016._05.ServiceGroup; -import org.oasis_open.docs.bdxr.ns.smp._2016._05.ServiceMetadataReferenceType; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.annotation.Rollback; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.jdbc.Sql; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.transaction.annotation.Transactional; -import org.xml.sax.SAXException; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.xml.parsers.ParserConfigurationException; -import java.io.IOException; -import java.util.List; - -import static eu.europa.ec.smp.api.Identifiers.asDocumentId; -import static eu.europa.ec.smp.api.Identifiers.asParticipantId; - -/** - * Created by gutowpa on 27/03/2017. - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {SmpServicesTestConfig.class}) -@Transactional -@Rollback(true) -@Sql("classpath:/service_integration_test_data.sql") -public class BaseServiceGroupInterfaceImplTest { - - private static String SERVICE_GROUP_ID = "eHealth-participantId-qns::urn:Poland:ncpb"; - private static String DOC_ID = "eHealth-resId-qns::DocId.007"; - - @Autowired - private BaseServiceGroupInterfaceImpl serviceGroupService; - - @Autowired - private DBMSDataManager dataManager; - - @PersistenceContext - private EntityManager entityManager; - - @Before - public void setUp() throws IOException, SAXException, ParserConfigurationException { - String sgXml = XmlTestUtils.loadDocumentAsString("/input/ServiceGroupPoland.xml"); - System.err.print(sgXml); - ServiceGroup serviceGroup = ServiceGroupConverter.unmarshal(sgXml); - dataManager.saveServiceGroup(serviceGroup, "test_admin"); - String smXml = XmlTestUtils.loadDocumentAsString("/input/ServiceMetadataPoland.xml"); - dataManager.saveService(asParticipantId(SERVICE_GROUP_ID), asDocumentId(DOC_ID), smXml); - - - - ServiceGroup sg = serviceGroupService.getServiceGroup(SERVICE_GROUP_ID); - List<ServiceMetadataReferenceType> serviceMetadataReferences = sg.getServiceMetadataReferenceCollection().getServiceMetadataReferences(); - System.out.print(serviceMetadataReferences.size()); - } - - @Test - public void testUrlsHandledByWebLayer() throws Throwable { - //when - ServiceGroup serviceGroup = serviceGroupService.getServiceGroup(SERVICE_GROUP_ID); - - //then - List<ServiceMetadataReferenceType> serviceMetadataReferences = serviceGroup.getServiceMetadataReferenceCollection().getServiceMetadataReferences(); - //URLs are handled in by the REST webservices layer - Assert.assertEquals(0, serviceMetadataReferences.size()); - } -} diff --git a/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/util/BusdoxURLUtilsTest.java b/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/util/BusdoxURLUtilsTest.java deleted file mode 100644 index 46698c003b1ad848499f576aa8ce117d2ea93d73..0000000000000000000000000000000000000000 --- a/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/util/BusdoxURLUtilsTest.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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.cipa.smp.server.util; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -/** - * Test class for class {@link BusdoxURLUtils}. - * - * @author PEPPOL.AT, BRZ, Philip Helger - */ -public final class BusdoxURLUtilsTest { - @Test - public void testCreatePercentEncodedURL () { - assertNull (BusdoxURLUtils.createPercentEncodedURL (null)); - assertEquals ("", BusdoxURLUtils.createPercentEncodedURL ("")); - assertEquals ("abc", BusdoxURLUtils.createPercentEncodedURL ("abc")); - assertEquals ("a%25b", BusdoxURLUtils.createPercentEncodedURL ("a%b")); - assertEquals ("a%25%25b", BusdoxURLUtils.createPercentEncodedURL ("a%%b")); - assertEquals ("a%2Fb", BusdoxURLUtils.createPercentEncodedURL ("a/b")); - } - -} diff --git a/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/util/CertificateUtilsTest.java b/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/util/CertificateUtilsTest.java index c0d469de1e734107e1368cc77b00c42d0b45be37..fd68457f6107f20fedaa8a861c652318fedfa419 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/util/CertificateUtilsTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/util/CertificateUtilsTest.java @@ -15,8 +15,7 @@ package eu.europa.ec.cipa.smp.server.util; -import eu.europa.ec.cipa.smp.server.AbstractTest; -import eu.europa.ec.cipa.smp.server.errors.exceptions.CertificateAuthenticationException; +import eu.europa.ec.edelivery.smp.exceptions.CertificateAuthenticationException; import eu.europa.ec.cipa.smp.server.security.CertificateDetails; import org.junit.Assert; import org.junit.Test; @@ -43,18 +42,18 @@ public class CertificateUtilsTest { @Test public void testReturnCertificateIdString() { Assert.assertEquals("TEST SUBJECT:000000008f658712", - CertificateUtils.returnCertificateId("TEST SUBJECT","8f658712")); + CertificateUtils.returnCertificateId("TEST SUBJECT", "8f658712")); } @Test public void testReturnCertificateIdStringWithHexaHeader() { Assert.assertEquals("TEST SUBJECT:000000008f658712", - CertificateUtils.returnCertificateId("TEST SUBJECT","0x8f658712")); + CertificateUtils.returnCertificateId("TEST SUBJECT", "0x8f658712")); } @Test public void testRemoveHexHeader() { - Assert.assertEquals("1234567890",CertificateUtils.removeHexHeader("0x1234567890")); + Assert.assertEquals("1234567890", CertificateUtils.removeHexHeader("0x1234567890")); } @Test diff --git a/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/util/IdentifierUtilsTest.java b/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/util/IdentifierUtilsTest.java index 8e5fc23425a6b9acb10460dae811cb87450271c0..1d5aff7ea927181a9b9da1d6a3809d4ff9be126c 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/util/IdentifierUtilsTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/util/IdentifierUtilsTest.java @@ -15,7 +15,7 @@ package eu.europa.ec.cipa.smp.server.util; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import eu.europa.ec.cipa.smp.server.data.dbms.model.CommonColumnsLengths; +import eu.europa.ec.edelivery.smp.data.model.CommonColumnsLengths; import org.junit.Test; import org.oasis_open.docs.bdxr.ns.smp._2016._05.DocumentIdentifier; import org.oasis_open.docs.bdxr.ns.smp._2016._05.ParticipantIdentifierType; @@ -28,22 +28,6 @@ import static org.junit.Assert.*; * @author PEPPOL.AT, BRZ, Philip Helger */ public final class IdentifierUtilsTest { - private static final String [] PARTICIPANT_SCHEME_VALID = { "bdxr-actorid-upis", - "bdxr-ACTORID-UPIS", - CommonColumnsLengths.DEFAULT_PARTICIPANT_IDENTIFIER_SCHEME, - "any-actorid-any", - "any-ACTORID-any" }; - private static final String [] PARTIFCIPANT_SCHEME_INVALID = { null, - "", - "bdxr_actorid_upis", - "bdxr-notactorid-upis", - "-actorid-upis", - "actorid-upis", - "bdxr-actorid-", - "bdxr-actorid", - "any-domain_actorid_any-type", - "any-nonactoid-anybutmuchtoooooooooooooooooooooooolong" }; - @Test public void testAreIdentifiersEqualPariticpantIdentifier () { diff --git a/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/util/KeyStoreUtilsTest.java b/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/util/KeyStoreUtilsTest.java index 208dc95892eb27dd8ebaae46916a414484c2f707..aafddf24be8c4cf7512deb93c38bdd2a3c26cef4 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/util/KeyStoreUtilsTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/util/KeyStoreUtilsTest.java @@ -124,8 +124,7 @@ public final class KeyStoreUtilsTest { @Test public void testLoadTrustStore () throws Exception { // Load trust store - final KeyStore aTrustStore = KeyStoreUtils.loadKeyStore (KeyStoreUtils.TRUSTSTORE_CLASSPATH, - KeyStoreUtils.TRUSTSTORE_PASSWORD); + final KeyStore aTrustStore = KeyStoreUtils.loadKeyStore (KeyStoreUtils.TRUSTSTORE_CLASSPATH,"peppol"); assertNotNull (aTrustStore); // Ensure all name entries are contained diff --git a/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/util/XmlTestUtils.java b/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/util/XmlTestUtils.java index f7859e4dce7f7d23fce980017d9af857438e8b3c..e4a24627615d0665c208bcfbd34272df6602b55d 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/util/XmlTestUtils.java +++ b/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/util/XmlTestUtils.java @@ -17,6 +17,7 @@ package eu.europa.ec.cipa.smp.server.util; import eu.europa.ec.cipa.smp.server.security.SignatureUtil; import org.apache.commons.io.IOUtils; +import org.oasis_open.docs.bdxr.ns.smp._2016._05.ServiceGroup; import org.oasis_open.docs.bdxr.ns.smp._2016._05.ServiceMetadata; import org.w3c.dom.Document; import org.w3c.dom.Node; @@ -73,4 +74,12 @@ public class XmlTestUtils { jaxbMarshaller.marshal(serviceMetadata, sw); return sw.toString(); } + + public static String marshall(ServiceGroup serviceGroup) throws JAXBException { + StringWriter sw = new StringWriter(); + JAXBContext jaxbContext = JAXBContext.newInstance(ServiceGroup.class); + Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); + jaxbMarshaller.marshal(serviceGroup, sw); + return sw.toString(); + } } diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/config/SmpServicesTestConfig.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/config/SmpServicesTestConfig.java index d0a8b7780114c1ce81b7d19b5ea226f2e65701c5..410d35269bb76e49f04a3de6bf0782e64c6cfcaf 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/config/SmpServicesTestConfig.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/config/SmpServicesTestConfig.java @@ -38,7 +38,11 @@ import javax.sql.DataSource; */ @Configuration @ComponentScan(basePackages = { - "eu.europa.ec.cipa.smp.server"}) + "eu.europa.ec.edelivery.smp.services", + "eu.europa.ec.edelivery.smp.data.dao", + "eu.europa.ec.cipa.smp.server.hook", + "eu.europa.ec.cipa.smp.server.conversion", + "eu.europa.ec.cipa.smp.server.util"}) @PropertySource(value = "classpath:config.properties") public class SmpServicesTestConfig { @@ -74,19 +78,12 @@ public class SmpServicesTestConfig { public LocalContainerEntityManagerFactoryBean smpEntityManagerFactory() { LocalContainerEntityManagerFactoryBean lef = new LocalContainerEntityManagerFactoryBean(); lef.setDataSource(dataSource()); - lef.setJpaVendorAdapter(jpaVendorAdapter()); - lef.setPackagesToScan("eu.europa.ec.cipa.smp.server.data.dbms.model"); - lef.setPersistenceXmlLocation("classpath:META-INF/smp-persistence.xml"); + lef.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); + lef.setPackagesToScan("eu.europa.ec.edelivery.smp.data.model"); + //lef.setPersistenceXmlLocation("classpath:META-INF/smp-persistence.xml"); return lef; } - @Bean - public JpaVendorAdapter jpaVendorAdapter() { - HibernateJpaVendorAdapter hibernateJpaVendorAdapter = new HibernateJpaVendorAdapter(); - - return hibernateJpaVendorAdapter; - } - @Bean public PlatformTransactionManager transactionManager(EntityManagerFactory emf) { JpaTransactionManager transactionManager = new JpaTransactionManager(); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ServiceGroupServiceIntegrationTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ServiceGroupServiceIntegrationTest.java new file mode 100644 index 0000000000000000000000000000000000000000..baea2f99b7508a1777620394772e82325fb5b31e --- /dev/null +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ServiceGroupServiceIntegrationTest.java @@ -0,0 +1,163 @@ +/* + * 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.services; + +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.model.DBOwnership; +import eu.europa.ec.edelivery.smp.data.model.DBOwnershipId; +import eu.europa.ec.edelivery.smp.data.model.DBServiceGroup; +import eu.europa.ec.edelivery.smp.exceptions.NotFoundException; +import eu.europa.ec.edelivery.smp.config.SmpServicesTestConfig; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.oasis_open.docs.bdxr.ns.smp._2016._05.ExtensionType; +import org.oasis_open.docs.bdxr.ns.smp._2016._05.ParticipantIdentifierType; +import org.oasis_open.docs.bdxr.ns.smp._2016._05.ServiceGroup; +import org.oasis_open.docs.bdxr.ns.smp._2016._05.ServiceMetadataReferenceType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.annotation.Rollback; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.transaction.annotation.Transactional; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.xml.bind.JAXBException; +import java.io.IOException; +import java.security.acl.Owner; +import java.util.List; + +import static eu.europa.ec.cipa.smp.server.conversion.ServiceGroupConverter.toDbModel; +import static eu.europa.ec.cipa.smp.server.conversion.ServiceGroupConverter.unmarshal; +import static eu.europa.ec.cipa.smp.server.util.XmlTestUtils.loadDocumentAsString; +import static eu.europa.ec.cipa.smp.server.util.XmlTestUtils.marshall; +import static eu.europa.ec.smp.api.Identifiers.asParticipantId; +import static org.junit.Assert.*; + +/** + * Created by gutowpa on 27/03/2017. + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = {SmpServicesTestConfig.class}) +@Transactional +@Rollback(true) +@Sql("classpath:/service_integration_test_data.sql") +public class ServiceGroupServiceIntegrationTest { + + private static final String SERVICE_GROUP_XML_PATH = "/eu/europa/ec/edelivery/smp/services/ServiceGroupPoland.xml"; + private static final ParticipantIdentifierType SERVICE_GROUP_ID = asParticipantId("participant-scheme-qns::urn:poland:ncpb"); + public static final String ADMIN_USERNAME = "test_admin"; + + @PersistenceContext + EntityManager em; + + @Autowired + ServiceGroupDao serviceGroupDao; + + @Autowired + OwnershipDao ownershipDao; + + @Autowired + private ServiceGroupService serviceGroupService; + + @Test + public void makeSureServiceGroupDoesNotExistAlready(){ + DBServiceGroup dbServiceGroup = serviceGroupDao.find(toDbModel(SERVICE_GROUP_ID)); + if(dbServiceGroup != null){ + throw new IllegalStateException("Underlying DB already contains test data that should not be there. Remove them manually."); + } + } + + @Test + public void saveAndReadPositiveScenario() throws IOException, JAXBException { + //when + ServiceGroup inServiceGroup = saveServiceGroup(); + ServiceGroup outServiceGroup = serviceGroupService.getServiceGroup(SERVICE_GROUP_ID); + + //then + assertFalse(inServiceGroup == outServiceGroup); + assertEquals(marshall(inServiceGroup), marshall(outServiceGroup)); + + em.flush(); + DBOwnership outOwnership = ownershipDao.find(new DBOwnershipId(ADMIN_USERNAME, SERVICE_GROUP_ID.getScheme(), SERVICE_GROUP_ID.getValue())); + assertEquals(ADMIN_USERNAME, outOwnership.getUser().getUsername()); + } + + @Test(expected = NotFoundException.class) + public void notFoundExceptionThrownWhenReadingNotExisting() { + serviceGroupService.getServiceGroup(asParticipantId("not-existing::service-group")); + } + + @Test + public void saveAndDeletePositiveScenario() throws IOException { + //given + saveServiceGroup(); + em.flush(); + + //when + serviceGroupService.deleteServiceGroup(SERVICE_GROUP_ID); + em.flush(); + + //then + try { + serviceGroupService.getServiceGroup(SERVICE_GROUP_ID); + } catch (NotFoundException e) { + return; + } + fail("ServiceGroup has not been deleted"); + } + + @Test + public void updatePositiveScenario() throws IOException, JAXBException { + //given + ServiceGroup oldServiceGroup = saveServiceGroup(); + + ServiceGroup newServiceGroup = unmarshal(loadDocumentAsString(SERVICE_GROUP_XML_PATH)); + ExtensionType newExtension = new ExtensionType(); + newExtension.setExtensionID("new extension ID"); + newServiceGroup.getExtensions().add(newExtension); + + //when + serviceGroupService.saveServiceGroup(newServiceGroup, ADMIN_USERNAME); + ServiceGroup resultServiceGroup = serviceGroupService.getServiceGroup(SERVICE_GROUP_ID); + + //then + assertNotEquals(marshall(oldServiceGroup), marshall(resultServiceGroup)); + assertEquals(marshall(newServiceGroup), marshall(resultServiceGroup)); + } + + @Test + public void urlsAreHandledByWebLayer() throws Throwable { + //given + saveServiceGroup(); + + //when + ServiceGroup serviceGroup = serviceGroupService.getServiceGroup(SERVICE_GROUP_ID); + + //then + List<ServiceMetadataReferenceType> serviceMetadataReferences = serviceGroup.getServiceMetadataReferenceCollection().getServiceMetadataReferences(); + //URLs are handled in by the REST webservices layer + assertEquals(0, serviceMetadataReferences.size()); + } + + private ServiceGroup saveServiceGroup() throws IOException { + ServiceGroup inServiceGroup = unmarshal(loadDocumentAsString(SERVICE_GROUP_XML_PATH)); + serviceGroupService.saveServiceGroup(inServiceGroup, ADMIN_USERNAME); + return inServiceGroup; + } +} diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ServiceMetadataIntegrationTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ServiceMetadataIntegrationTest.java new file mode 100644 index 0000000000000000000000000000000000000000..2243f2b03454b434ec63aba1ab064f9f379238f3 --- /dev/null +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ServiceMetadataIntegrationTest.java @@ -0,0 +1,201 @@ +/* + * 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.services; + +import eu.europa.ec.cipa.smp.server.conversion.ServiceGroupConverter; +import eu.europa.ec.cipa.smp.server.conversion.ServiceMetadataConverter; +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.exceptions.NotFoundException; +import eu.europa.ec.edelivery.smp.config.SmpServicesTestConfig; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.oasis_open.docs.bdxr.ns.smp._2016._05.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.annotation.Rollback; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.transaction.annotation.Transactional; +import org.w3c.dom.Document; + +import javax.persistence.EntityManager; +import javax.persistence.EntityNotFoundException; +import javax.persistence.PersistenceContext; +import javax.xml.bind.JAXBException; +import javax.xml.transform.TransformerException; +import java.io.IOException; +import java.util.List; + +import static eu.europa.ec.cipa.smp.server.conversion.ServiceGroupConverter.toDbModel; +import static eu.europa.ec.cipa.smp.server.conversion.ServiceMetadataConverter.unmarshal; +import static eu.europa.ec.cipa.smp.server.util.XmlTestUtils.loadDocumentAsString; +import static eu.europa.ec.cipa.smp.server.util.XmlTestUtils.marshall; +import static eu.europa.ec.smp.api.Identifiers.asDocumentId; +import static eu.europa.ec.smp.api.Identifiers.asParticipantId; +import static org.junit.Assert.*; + +/** + * Created by gutowpa on 15/11/2017. + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = {SmpServicesTestConfig.class}) +@Transactional +@Rollback(true) +@Sql("classpath:/service_integration_test_data.sql") +public class ServiceMetadataIntegrationTest { + + private static final String SERVICE_GROUP_XML_PATH = "/eu/europa/ec/edelivery/smp/services/ServiceGroupPoland.xml"; + private static final String SERVICE_METADATA_XML_PATH = "/eu/europa/ec/edelivery/smp/services/ServiceMetadataPoland.xml"; + private static final String SIGNED_SERVICE_METADATA_XML_PATH = "/eu/europa/ec/edelivery/smp/services/SignedServiceMetadataPoland.xml"; + private static final ParticipantIdentifierType SERVICE_GROUP_ID = asParticipantId("participant-scheme-qns::urn:poland:ncpb"); + private static final DocumentIdentifier DOC_ID = asDocumentId("ehealth-resid-qns::docid.007"); + public static final String ADMIN_USERNAME = "test_admin"; + + @Autowired + ServiceMetadataService serviceMetadataService; + + @Autowired + ServiceGroupService serviceGroupService; + + @PersistenceContext + EntityManager em; + + @Autowired + private ServiceMetadataDao serviceMetadataDao; + + @Before + public void before() throws IOException { + ServiceGroup inServiceGroup = ServiceGroupConverter.unmarshal(loadDocumentAsString(SERVICE_GROUP_XML_PATH)); + serviceGroupService.saveServiceGroup(inServiceGroup, ADMIN_USERNAME); + } + + @Test + public void makeSureServiceMetadataDoesNotExistAlready(){ + DBServiceMetadata dbServiceMetadata = serviceMetadataDao.find(ServiceMetadataConverter.toDbModel(SERVICE_GROUP_ID, DOC_ID)); + if(dbServiceMetadata != null){ + throw new IllegalStateException("Underlying DB already contains test data that should not be there. Remove them manually."); + } + } + + @Test + public void saveAndReadPositiveScenario() throws IOException, TransformerException, JAXBException { + //given + String inServiceMetadataXml = loadDocumentAsString(SERVICE_METADATA_XML_PATH); + String expectedSignedServiceMetadataXml = loadDocumentAsString(SIGNED_SERVICE_METADATA_XML_PATH); + List<DocumentIdentifier> docIdsBefore = serviceMetadataService.findServiceMetadataIdentifiers(SERVICE_GROUP_ID); + assertEquals(0, docIdsBefore.size()); + + //when + serviceMetadataService.saveServiceMetadata(SERVICE_GROUP_ID, DOC_ID, inServiceMetadataXml); + Document outServiceMetadataDoc = serviceMetadataService.getServiceMetadataDocument(SERVICE_GROUP_ID, DOC_ID); + + //then + assertEquals(expectedSignedServiceMetadataXml, ServiceMetadataConverter.toString(outServiceMetadataDoc)); + List<DocumentIdentifier> docIdsAfter = serviceMetadataService.findServiceMetadataIdentifiers(SERVICE_GROUP_ID); + assertEquals(1, docIdsAfter.size()); + assertTrue(DOC_ID.equals(docIdsAfter.get(0))); + } + + @Test(expected = NotFoundException.class) + public void notFoundExceptionThrownWhenReadingNotExisting() { + serviceMetadataService.getServiceMetadataDocument(SERVICE_GROUP_ID, DOC_ID); + } + + @Test(expected = NotFoundException.class) + public void notFoundExceptionThrownWhenDeletingNotExisting() { + serviceMetadataService.deleteServiceMetadata(SERVICE_GROUP_ID, DOC_ID); + } + + @Test + public void saveAndDeletePositiveScenario() throws IOException { + //given + String inServiceMetadataXml = loadDocumentAsString(SERVICE_METADATA_XML_PATH); + serviceMetadataService.saveServiceMetadata(SERVICE_GROUP_ID, DOC_ID, inServiceMetadataXml); + List<DocumentIdentifier> docIdsBefore = serviceMetadataService.findServiceMetadataIdentifiers(SERVICE_GROUP_ID); + assertEquals(1, docIdsBefore.size()); + DBServiceMetadata dbServiceMetadata = serviceMetadataDao.find(ServiceMetadataConverter.toDbModel(SERVICE_GROUP_ID, DOC_ID)); + assertNotNull(dbServiceMetadata); + + //when + serviceMetadataService.deleteServiceMetadata(SERVICE_GROUP_ID, DOC_ID); + + //then + List<DocumentIdentifier> docIdsAfter = serviceMetadataService.findServiceMetadataIdentifiers(SERVICE_GROUP_ID); + assertEquals(0, docIdsAfter.size()); + try { + em.refresh(dbServiceMetadata); + }catch (EntityNotFoundException e){ + // expected and needed - Hibernate's changes made on the same entity + // by persist() and Queries were not aware of each other + } + + try { + serviceMetadataService.getServiceMetadataDocument(SERVICE_GROUP_ID, DOC_ID); + } catch (NotFoundException e) { + return; + } + fail("ServiceMetadata has not been deleted"); + } + + @Test + public void updatePositiveScenario() throws IOException, JAXBException, TransformerException { + //given + String oldServiceMetadataXml = loadDocumentAsString(SERVICE_METADATA_XML_PATH); + serviceMetadataService.saveServiceMetadata(SERVICE_GROUP_ID, DOC_ID, oldServiceMetadataXml); + + ServiceMetadata newServiceMetadata = unmarshal(loadDocumentAsString(SERVICE_METADATA_XML_PATH)); + EndpointType endpoint = newServiceMetadata.getServiceInformation().getProcessList().getProcesses().get(0).getServiceEndpointList().getEndpoints().get(0); + endpoint.setServiceDescription("New Description"); + String newServiceMetadataXml = marshall(newServiceMetadata); + serviceMetadataService.saveServiceMetadata(SERVICE_GROUP_ID, DOC_ID, newServiceMetadataXml); + + //when + Document resultServiceMetadataDoc = serviceMetadataService.getServiceMetadataDocument(SERVICE_GROUP_ID, DOC_ID); + + //then + 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()); + } +} diff --git a/smp-server-library/src/test/resources/eu/europa/ec/edelivery/smp/services/ServiceGroupPoland.xml b/smp-server-library/src/test/resources/eu/europa/ec/edelivery/smp/services/ServiceGroupPoland.xml new file mode 100644 index 0000000000000000000000000000000000000000..162d5579f5e001985ca3d10ef5a214abcfc4a505 --- /dev/null +++ b/smp-server-library/src/test/resources/eu/europa/ec/edelivery/smp/services/ServiceGroupPoland.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<ServiceGroup xmlns="http://docs.oasis-open.org/bdxr/ns/SMP/2016/05"> + <ParticipantIdentifier scheme="participant-scheme-qns">urn:poland:ncpb</ParticipantIdentifier> + <ServiceMetadataReferenceCollection/> + <Extension> + <CustomNode xmlns="http://custom.com/schema1">Any XML content 1</CustomNode> + <ExtensionAgencyID>Agency ID 1</ExtensionAgencyID> + <ExtensionAgencyName>Agency name 1</ExtensionAgencyName> + </Extension> + <Extension> + <CustomNode xmlns="http://custom.com/schema2">Any XML content 2</CustomNode> + <ExtensionAgencyID>Agency ID 2</ExtensionAgencyID> + <ExtensionAgencyName>Agency name 2</ExtensionAgencyName> + </Extension> +</ServiceGroup> \ No newline at end of file diff --git a/smp-server-library/src/test/resources/eu/europa/ec/edelivery/smp/services/ServiceMetadataPoland.xml b/smp-server-library/src/test/resources/eu/europa/ec/edelivery/smp/services/ServiceMetadataPoland.xml new file mode 100644 index 0000000000000000000000000000000000000000..7221de38cd04d015f8783e97b74b9b7c0075383b --- /dev/null +++ b/smp-server-library/src/test/resources/eu/europa/ec/edelivery/smp/services/ServiceMetadataPoland.xml @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<ServiceMetadata xmlns="http://docs.oasis-open.org/bdxr/ns/SMP/2016/05"> + <ServiceInformation> + <ParticipantIdentifier scheme="eHealth-participantId-qns">urn:Poland:ncpb</ParticipantIdentifier> + <DocumentIdentifier scheme="eHealth-resId-qns">DocId.007</DocumentIdentifier> + <ProcessList> + <Process> + <ProcessIdentifier scheme="ehealth-procid-qns">urn:epsosPatientService::List</ProcessIdentifier> + <ServiceEndpointList> + <Endpoint transportProfile="urn:ihe:iti:2013:xcpd"> + <EndpointURI>http://poland.pl/ncp/patient/list</EndpointURI> + <RequireBusinessLevelSignature>false</RequireBusinessLevelSignature> + <MinimumAuthenticationLevel>urn:epSOS:loa:1</MinimumAuthenticationLevel> + <ServiceActivationDate>2016-06-06T11:06:02.000+02:00</ServiceActivationDate> + <ServiceExpirationDate>2026-06-06T11:06:02+02:00</ServiceExpirationDate> + <Certificate>MIIFMTCCAxmgAwIBAgICEBAwDQYJKoZIhvcNAQELBQAwgbwxCzAJBgNVBAYTAkJFMRAwDgYDVQQIDAdCZWxnaXVtMRowGAYDVQQKDBFDb25uZWN0aXZpdHkgVGVzdDEjMCEGA1UECwwaQ29ubmVjdGluZyBFdXJvcGUgRmFjaWxpdHkxJzAlBgNVBAMMHkNvbm5lY3Rpdml0eSBUZXN0IENvbXBvbmVudCBDQTExMC8GCSqGSIb3DQEJARYiQ0VGLUVERUxJVkVSWS1TVVBQT1JUQGVjLmV1cm9wYS5ldTAeFw0xNzEwMTIxMjU3NDJaFw0yODAxMTgxMjU3NDJaMIG1MQswCQYDVQQGEwJQTDEsMCoGA1UECgwjREXhup7Dn8OEw6RQTMW8w7PFgsSHTk/DhsOmw5jDuMOFw6UxeDB2BgNVBAMMb3NsYXNoL2JhY2tzbGFzaFxxdW90ZSJjb2xvbjpfcmZjMjI1M3NwZWNpYWxfYW1wZXJzYW5kJmNvbW1hLGVxdWFscz1wbHVzK2xlc3N0aGFuPGdyZWF0ZXJ0aGFuPmhhc2gjc2VtaWNvbG9uO2VuZDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAudajaE8sHeL7qWied2Nf0dEreOLu+cDIluWBczKF7hxmRJ4VJ3y/TN/SilBN1gqBCJtsiGhsf66w5dIPJFNHj68YL5Evi5lkfLqMNRbKN08oLN6T2aIEcg+/T4OLyonNLrUMtOkpAi3swKTanOLwOqp/cu53Vgi94FfvCzCtkgkCAwEAAaOBxTCBwjAJBgNVHRMEAjAAMBEGCWCGSAGG+EIBAQQEAwIFoDAzBglghkgBhvhCAQ0EJhYkT3BlblNTTCBHZW5lcmF0ZWQgQ2xpZW50IENlcnRpZmljYXRlMB0GA1UdDgQWBBR3wx7TpvKZzhO3cWBTSkXrcJVPfjAfBgNVHSMEGDAWgBS96Nd21/ujY1YLoaLGA7dspLBPLTAOBgNVHQ8BAf8EBAMCBeAwHQYDVR0lBBYwFAYIKwYBBQUHAwIGCCsGAQUFBwMEMA0GCSqGSIb3DQEBCwUAA4ICAQAoVlGu/1u1HSmPDnn1dJalBG2yfBpcmiu163FSCiF4o5PDZfSEMbIMVkw1HsA3b78uhfduP/yaGICzqqCEKBA4dYeFiFCkkuJZD/c3MeFp8h646BzwFrAOWXOEhtg+Afl5fRAJQ64zJ8igGybP4GsrHt1282waKkfE+DRWTvU81tyA98GpG/gRJY8VvCyu3Is9za2xr9RtGjXWI1cdwIkTXk6GoLjUaH6QIb9ewuYGEVNPZmV6qFqqfCU54z7lPw5G7wvE86ggIszixbpUK2IGKLNonpyKe0UFUB9uhRbcynCYbJWpVykZLQ1noRna4XMkfEvmknzA7bJd6WBX82yDXYE6omFqJ5JB6iNt/yswF7cZ2sRKwbsl6P1Z3Lhj2qYYdEt73TQwztY9ZBwpriG5E4RaZzolpTzZ3GkzLPv1kww+MFCW4H7M6M1sMpOYDq+hCw8EGzTn2QTuqtzPJr9n3tlTkKif78h1mooxHlyDjuky4Fhh3tzjblLf+e9lZh8H8XTBCHvG7nilKwhY93RipP2av6hw1l+l1vqj/1KM9DFWuWZhp3koyBw4RuyH5OPgHBBczft/XmLeuFjw+bv7Qle5ObxcLbaJzusgKgl5D1982YejA8Tnw4bbMXk0WmFiaEA39keusEjKG4JGAy1RZdJuDISR6pANGDENYsFSPw==</Certificate> + <ServiceDescription>This is the epSOS Patient Service List for the Polish NCP</ServiceDescription> + <TechnicalContactUrl>http://poland.pl/contact</TechnicalContactUrl> + <TechnicalInformationUrl>http://poland.pl/contact</TechnicalInformationUrl> + </Endpoint> + </ServiceEndpointList> + </Process> + </ProcessList> + <Extension> + <CustomNode xmlns="http://custom.com/schema1">Any XML content 1</CustomNode> + <ExtensionAgencyID>Agency ID 1</ExtensionAgencyID> + <ExtensionAgencyName>Agency name 1</ExtensionAgencyName> + </Extension> + <Extension> + <CustomNode xmlns="http://custom.com/schema2">Any XML content 2</CustomNode> + <ExtensionAgencyID>Agency ID 2</ExtensionAgencyID> + <ExtensionAgencyName>Agency name 2</ExtensionAgencyName> + </Extension> + </ServiceInformation> +</ServiceMetadata> \ No newline at end of file diff --git a/smp-server-library/src/test/resources/eu/europa/ec/edelivery/smp/services/SignedServiceMetadataPoland.xml b/smp-server-library/src/test/resources/eu/europa/ec/edelivery/smp/services/SignedServiceMetadataPoland.xml new file mode 100644 index 0000000000000000000000000000000000000000..1843e834d051daf5c327c3ae742bdd4c1f4d71d8 --- /dev/null +++ b/smp-server-library/src/test/resources/eu/europa/ec/edelivery/smp/services/SignedServiceMetadataPoland.xml @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?><SignedServiceMetadata xmlns="http://docs.oasis-open.org/bdxr/ns/SMP/2016/05"><ServiceMetadata> + <ServiceInformation> + <ParticipantIdentifier scheme="eHealth-participantId-qns">urn:Poland:ncpb</ParticipantIdentifier> + <DocumentIdentifier scheme="eHealth-resId-qns">DocId.007</DocumentIdentifier> + <ProcessList> + <Process> + <ProcessIdentifier scheme="ehealth-procid-qns">urn:epsosPatientService::List</ProcessIdentifier> + <ServiceEndpointList> + <Endpoint transportProfile="urn:ihe:iti:2013:xcpd"> + <EndpointURI>http://poland.pl/ncp/patient/list</EndpointURI> + <RequireBusinessLevelSignature>false</RequireBusinessLevelSignature> + <MinimumAuthenticationLevel>urn:epSOS:loa:1</MinimumAuthenticationLevel> + <ServiceActivationDate>2016-06-06T11:06:02.000+02:00</ServiceActivationDate> + <ServiceExpirationDate>2026-06-06T11:06:02+02:00</ServiceExpirationDate> + <Certificate>MIIFMTCCAxmgAwIBAgICEBAwDQYJKoZIhvcNAQELBQAwgbwxCzAJBgNVBAYTAkJFMRAwDgYDVQQIDAdCZWxnaXVtMRowGAYDVQQKDBFDb25uZWN0aXZpdHkgVGVzdDEjMCEGA1UECwwaQ29ubmVjdGluZyBFdXJvcGUgRmFjaWxpdHkxJzAlBgNVBAMMHkNvbm5lY3Rpdml0eSBUZXN0IENvbXBvbmVudCBDQTExMC8GCSqGSIb3DQEJARYiQ0VGLUVERUxJVkVSWS1TVVBQT1JUQGVjLmV1cm9wYS5ldTAeFw0xNzEwMTIxMjU3NDJaFw0yODAxMTgxMjU3NDJaMIG1MQswCQYDVQQGEwJQTDEsMCoGA1UECgwjREXhup7Dn8OEw6RQTMW8w7PFgsSHTk/DhsOmw5jDuMOFw6UxeDB2BgNVBAMMb3NsYXNoL2JhY2tzbGFzaFxxdW90ZSJjb2xvbjpfcmZjMjI1M3NwZWNpYWxfYW1wZXJzYW5kJmNvbW1hLGVxdWFscz1wbHVzK2xlc3N0aGFuPGdyZWF0ZXJ0aGFuPmhhc2gjc2VtaWNvbG9uO2VuZDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAudajaE8sHeL7qWied2Nf0dEreOLu+cDIluWBczKF7hxmRJ4VJ3y/TN/SilBN1gqBCJtsiGhsf66w5dIPJFNHj68YL5Evi5lkfLqMNRbKN08oLN6T2aIEcg+/T4OLyonNLrUMtOkpAi3swKTanOLwOqp/cu53Vgi94FfvCzCtkgkCAwEAAaOBxTCBwjAJBgNVHRMEAjAAMBEGCWCGSAGG+EIBAQQEAwIFoDAzBglghkgBhvhCAQ0EJhYkT3BlblNTTCBHZW5lcmF0ZWQgQ2xpZW50IENlcnRpZmljYXRlMB0GA1UdDgQWBBR3wx7TpvKZzhO3cWBTSkXrcJVPfjAfBgNVHSMEGDAWgBS96Nd21/ujY1YLoaLGA7dspLBPLTAOBgNVHQ8BAf8EBAMCBeAwHQYDVR0lBBYwFAYIKwYBBQUHAwIGCCsGAQUFBwMEMA0GCSqGSIb3DQEBCwUAA4ICAQAoVlGu/1u1HSmPDnn1dJalBG2yfBpcmiu163FSCiF4o5PDZfSEMbIMVkw1HsA3b78uhfduP/yaGICzqqCEKBA4dYeFiFCkkuJZD/c3MeFp8h646BzwFrAOWXOEhtg+Afl5fRAJQ64zJ8igGybP4GsrHt1282waKkfE+DRWTvU81tyA98GpG/gRJY8VvCyu3Is9za2xr9RtGjXWI1cdwIkTXk6GoLjUaH6QIb9ewuYGEVNPZmV6qFqqfCU54z7lPw5G7wvE86ggIszixbpUK2IGKLNonpyKe0UFUB9uhRbcynCYbJWpVykZLQ1noRna4XMkfEvmknzA7bJd6WBX82yDXYE6omFqJ5JB6iNt/yswF7cZ2sRKwbsl6P1Z3Lhj2qYYdEt73TQwztY9ZBwpriG5E4RaZzolpTzZ3GkzLPv1kww+MFCW4H7M6M1sMpOYDq+hCw8EGzTn2QTuqtzPJr9n3tlTkKif78h1mooxHlyDjuky4Fhh3tzjblLf+e9lZh8H8XTBCHvG7nilKwhY93RipP2av6hw1l+l1vqj/1KM9DFWuWZhp3koyBw4RuyH5OPgHBBczft/XmLeuFjw+bv7Qle5ObxcLbaJzusgKgl5D1982YejA8Tnw4bbMXk0WmFiaEA39keusEjKG4JGAy1RZdJuDISR6pANGDENYsFSPw==</Certificate> + <ServiceDescription>This is the epSOS Patient Service List for the Polish NCP</ServiceDescription> + <TechnicalContactUrl>http://poland.pl/contact</TechnicalContactUrl> + <TechnicalInformationUrl>http://poland.pl/contact</TechnicalInformationUrl> + </Endpoint> + </ServiceEndpointList> + </Process> + </ProcessList> + <Extension> + <CustomNode xmlns="http://custom.com/schema1">Any XML content 1</CustomNode> + <ExtensionAgencyID>Agency ID 1</ExtensionAgencyID> + <ExtensionAgencyName>Agency name 1</ExtensionAgencyName> + </Extension> + <Extension> + <CustomNode xmlns="http://custom.com/schema2">Any XML content 2</CustomNode> + <ExtensionAgencyID>Agency ID 2</ExtensionAgencyID> + <ExtensionAgencyName>Agency name 2</ExtensionAgencyName> + </Extension> + </ServiceInformation> +</ServiceMetadata><Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/><SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/><Reference URI=""><Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/></Transforms><DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/><DigestValue>bX6lTuxT21gbMILjxDoWzPYIZ4aQYu3iflyhpuLawys=</DigestValue></Reference></SignedInfo><SignatureValue>NQkzaoSBu9/Y7AilnxgX6/LM3A0g5WrDyxMEih9BbgnowPk24bNixc0A6kAI2Sp2MNojZUBRFue6 +uADhnQapRK4dRcAtHe2+Ao/SBHRP6233mghPosd4Y9Sw6hQ0wwziio5koa8bO5qtP5TjaVU8Yggo +MsTCeW2rFgFFzPtZ4ac=</SignatureValue><KeyInfo><X509Data><X509SubjectName>CN=SMP Mock Services,OU=DIGIT,O=European Commision,C=BE</X509SubjectName><X509Certificate>MIICIzCCAYygAwIBAgIEWCRzfjANBgkqhkiG9w0BAQsFADBWMQswCQYDVQQGEwJCRTEbMBkGA1UE +CgwSRXVyb3BlYW4gQ29tbWlzaW9uMQ4wDAYDVQQLDAVESUdJVDEaMBgGA1UEAwwRU01QIE1vY2sg +U2VydmljZXMwHhcNMTYxMTEwMTMxODE4WhcNMjYxMTEwMTMxODE4WjBWMQswCQYDVQQGEwJCRTEb +MBkGA1UECgwSRXVyb3BlYW4gQ29tbWlzaW9uMQ4wDAYDVQQLDAVESUdJVDEaMBgGA1UEAwwRU01Q +IE1vY2sgU2VydmljZXMwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBALrpN2GGqctPTP27g+zA +DCmQxdOZgDQg5AeF/N5w0knZYy1GnqvAoXgLGHeS1l+2DKx4/E6SlcU6SLIGhVtpF+Gitdp+3to2 +6FfV5qcCy4XKz1xm19r84ykXPWD835DbGB7o1HSlKx4+GmAr5eL2VH/zgINcJojam3gimvedoNWj +AgMBAAEwDQYJKoZIhvcNAQELBQADgYEAXoh7T9eYOdjasnzPfsTeQ1ptEorj4pIZMRFjn2BWl+mZ +K4XRn2+doLjN2dHremGyeKBgLb0Ulp9E9I5P8kxuIs7TjroxZofK9ixhfBv5rJhLcHy8XdrUYqAS +awc3c5bM9fNxRWCMkNYNoSYVxPBdlS4zEeLNNzRY+wjrMNYIJR4=</X509Certificate></X509Data></KeyInfo></Signature></SignedServiceMetadata> \ No newline at end of file diff --git a/smp-server-library/src/test/resources/input/ServiceGroupPoland.xml b/smp-server-library/src/test/resources/input/ServiceGroupPoland.xml deleted file mode 100644 index 853953f010b3843a5d56020d8e26e5b844b6290e..0000000000000000000000000000000000000000 --- a/smp-server-library/src/test/resources/input/ServiceGroupPoland.xml +++ /dev/null @@ -1,5 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<ServiceGroup xmlns="http://docs.oasis-open.org/bdxr/ns/SMP/2016/05"> - <ParticipantIdentifier scheme="eHealth-participantId-qns">urn:Poland:ncpb</ParticipantIdentifier> - <ServiceMetadataReferenceCollection/> -</ServiceGroup> \ No newline at end of file diff --git a/smp-server-library/src/test/resources/input/ServiceMetadataPoland.xml b/smp-server-library/src/test/resources/input/ServiceMetadataPoland.xml deleted file mode 100644 index 7cac3b90cca96c0eba79dbaf62aacff27477bffd..0000000000000000000000000000000000000000 --- a/smp-server-library/src/test/resources/input/ServiceMetadataPoland.xml +++ /dev/null @@ -1,26 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<ServiceMetadata xmlns="http://docs.oasis-open.org/bdxr/ns/SMP/2016/05"> - <ServiceInformation> - <ParticipantIdentifier scheme="eHealth-participantId-qns">urn:Poland:ncpb</ParticipantIdentifier> - <DocumentIdentifier scheme="eHealth-resId-qns">DocId.007</DocumentIdentifier> - <ProcessList> - <Process> - <ProcessIdentifier scheme="ehealth-procid-qns">urn:epsosPatientService::List</ProcessIdentifier> - <ServiceEndpointList> - <Endpoint transportProfile="urn:ihe:iti:2013:xcpd"> - <EndpointURI>http://poland.pl/ncp/patient/list</EndpointURI> - <RequireBusinessLevelSignature>false</RequireBusinessLevelSignature> - <MinimumAuthenticationLevel>urn:epSOS:loa:1</MinimumAuthenticationLevel> - <ServiceActivationDate>2016-06-06T11:06:02.000+02:00</ServiceActivationDate> - <ServiceExpirationDate>2026-06-06T11:06:02+02:00</ServiceExpirationDate> - <Certificate>MIID7jCCA1egAwIBAgICA+YwDQYJKoZIhvcNAQENBQAwOjELMAkGA1UEBhMCRlIxEzARBgNVBAoMCklIRSBFdXJvcGUxFjAUBgNVBAMMDUlIRSBFdXJvcGUgQ0EwHhcNMTYwNjAxMTQzNTUzWhcNMjYwNjAxMTQzNTUzWjCBgzELMAkGA1UEBhMCUFQxDDAKBgNVBAoMA01vSDENMAsGA1UECwwEU1BNUzENMAsGA1UEKgwESm9hbzEOMAwGA1UEBRMFQ3VuaGExHTAbBgNVBAMMFHFhZXBzb3MubWluLXNhdWRlLnB0MRkwFwYDVQQMDBBTZXJ2aWNlIFByb3ZpZGVyMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1eN4qPSSRZqjVFG9TlcPlxf2WiSimQK9L1nf9Z/s0ezeGQjCukDeDq/Wzqd9fpHhaMMq+XSSOtyEtIr5K/As4kFrViONUUkG12J6UllSWogp0NYFwA4wIqKSFiTnQS5/nRTs05oONCCGILCyJNNeO53JzPlaq3/QbPLssuSAr6XucPE8wBBGM8b/TsB2G/zjG8yuSTgGbhaZekq/Vnf9ftj1fr/vJDDAQgH6Yvzd88Z0DACJPHfW1p4F/OWLI386Bq7g/bo1DUPAyEwlf+CkLgJWRKki3yJlOCIZ9enMA5O7rfeG3rXdgYGmWS7tNEgKXxgC+heiYvi7ZWd7M+/SUwIDAQABo4IBMzCCAS8wPgYDVR0fBDcwNTAzoDGgL4YtaHR0cHM6Ly9nYXplbGxlLmloZS5uZXQvcGtpL2NybC82NDMvY2FjcmwuY3JsMDwGCWCGSAGG+EIBBAQvFi1odHRwczovL2dhemVsbGUuaWhlLm5ldC9wa2kvY3JsLzY0My9jYWNybC5jcmwwPAYJYIZIAYb4QgEDBC8WLWh0dHBzOi8vZ2F6ZWxsZS5paGUubmV0L3BraS9jcmwvNjQzL2NhY3JsLmNybDAfBgNVHSMEGDAWgBTsMw4TyCJeouFrr0N7el3Sd3MdfjAdBgNVHQ4EFgQU1GQ/K1ykIwWFgiONzWJLQzufF/8wDAYDVR0TAQH/BAIwADAOBgNVHQ8BAf8EBAMCBSAwEwYDVR0lBAwwCgYIKwYBBQUHAwEwDQYJKoZIhvcNAQENBQADgYEAZ7t1Qkr9wz3q6+WcF6p/YX7Jr0CzVe7w58FvJFk2AsHeYkSlOyO5hxNpQbs1L1v6JrcqziNFrh2QKGT2v6iPdWtdCT8HBLjmuvVWxxnfzYjdQ0J+kdKMAEV6EtWU78OqL60CCtUZKXE/NKJUq7TTUCFP2fwiARy/t1dTD2NZo8c=</Certificate> - <ServiceDescription>This is the epSOS Patient Service List for the Polish NCP</ServiceDescription> - <TechnicalContactUrl>http://poland.pl/contact</TechnicalContactUrl> - <TechnicalInformationUrl>http://poland.pl/contact</TechnicalInformationUrl> - </Endpoint> - </ServiceEndpointList> - </Process> - </ProcessList> - <Extension></Extension> - </ServiceInformation> -</ServiceMetadata> \ No newline at end of file diff --git a/smp-webapp/pom.xml b/smp-webapp/pom.xml index b94ba46bb7a8c7fbcf129fa66f149e37c12ebfb8..c3ca54394757d1f4a69f47c9747054f2b0423005 100644 --- a/smp-webapp/pom.xml +++ b/smp-webapp/pom.xml @@ -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> diff --git a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/config/DatabaseConfig.java b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/config/DatabaseConfig.java index 2c1487ca109e0d2810bc2088e441cc75c2ee5b40..47f47a32f056be9e43e3f2efe7eb5ee35a4c4866 100644 --- a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/config/DatabaseConfig.java +++ b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/config/DatabaseConfig.java @@ -19,10 +19,8 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; import org.springframework.jdbc.datasource.DriverManagerDataSource; import org.springframework.orm.jpa.JpaTransactionManager; -import org.springframework.orm.jpa.JpaVendorAdapter; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; import org.springframework.transaction.PlatformTransactionManager; @@ -38,7 +36,7 @@ import javax.sql.DataSource; @Configuration @EnableTransactionManagement @ComponentScan(basePackages = { - "eu.europa.ec.cipa.smp.server.data.dbms", + "eu.europa.ec.edelivery.smp.data.dao", "eu.europa.ec.cipa.smp.server.services", "eu.europa.ec.cipa.smp.server.hook"}) public class DatabaseConfig { @@ -70,21 +68,14 @@ public class DatabaseConfig { public LocalContainerEntityManagerFactoryBean smpEntityManagerFactory() { LocalContainerEntityManagerFactoryBean lef = new LocalContainerEntityManagerFactoryBean(); lef.setDataSource(dataSource()); - lef.setJpaVendorAdapter(jpaVendorAdapter()); - lef.setPackagesToScan("eu.europa.ec.cipa.smp.server.data.dbms.model"); - lef.setPersistenceXmlLocation("classpath:META-INF/smp-persistence.xml"); + lef.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); + lef.setPackagesToScan("eu.europa.ec.edelivery.smp.data.model"); + //lef.setPersistenceXmlLocation("classpath:META-INF/smp-persistence.xml"); return lef; } @Bean - public JpaVendorAdapter jpaVendorAdapter() { - HibernateJpaVendorAdapter hibernateJpaVendorAdapter = new HibernateJpaVendorAdapter(); - - return hibernateJpaVendorAdapter; - } - - @Bean - public PlatformTransactionManager transactionManager(EntityManagerFactory emf) { + public PlatformTransactionManager smpTransactionManager(EntityManagerFactory emf) { JpaTransactionManager transactionManager = new JpaTransactionManager(); transactionManager.setEntityManagerFactory(emf); diff --git a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/config/SmpAppConfig.java b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/config/SmpAppConfig.java index 76621330d7d1fd4aaba7528955dc39f274017b0f..ac0f45fd59d4cf9e469ba2484148ec6a4d0f5e42 100644 --- a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/config/SmpAppConfig.java +++ b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/config/SmpAppConfig.java @@ -26,8 +26,8 @@ import org.springframework.context.annotation.Import; @Configuration @ComponentScan(basePackages = { "eu.europa.ec.edelivery.smp.validation", - "eu.europa.ec.cipa.smp.server.data.dbms", - "eu.europa.ec.cipa.smp.server.services", + "eu.europa.ec.edelivery.smp.services", + "eu.europa.ec.edelivery.smp.data.dao", "eu.europa.ec.cipa.smp.server.hook", "eu.europa.ec.cipa.smp.server.conversion", "eu.europa.ec.cipa.smp.server.util"}) diff --git a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/controllers/ServiceGroupController.java b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/controllers/ServiceGroupController.java index 69ec28997552a5e33df822c7394f456f4602d43d..0bfdca79dd57061075636f922783823da9dbccd1 100644 --- a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/controllers/ServiceGroupController.java +++ b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/controllers/ServiceGroupController.java @@ -15,11 +15,9 @@ package eu.europa.ec.edelivery.smp.controllers; -import eu.europa.ec.cipa.smp.server.conversion.CaseSensitivityNormalizer; import eu.europa.ec.cipa.smp.server.conversion.ServiceGroupConverter; -import eu.europa.ec.cipa.smp.server.data.dbms.DBMSDataManager; -import eu.europa.ec.cipa.smp.server.services.BaseServiceGroupInterfaceImpl; -import eu.europa.ec.cipa.smp.server.services.BaseServiceMetadataInterfaceImpl; +import eu.europa.ec.edelivery.smp.services.ServiceGroupService; +import eu.europa.ec.edelivery.smp.services.ServiceMetadataService; import eu.europa.ec.edelivery.smp.validation.ServiceGroupValidator; import eu.europa.ec.smp.api.Identifiers; import eu.europa.ec.smp.api.exceptions.XmlInvalidAgainstSchemaException; @@ -39,7 +37,7 @@ import org.springframework.web.bind.annotation.*; import java.util.List; -import static eu.europa.ec.smp.api.Identifiers.asString; +import static eu.europa.ec.smp.api.Identifiers.asParticipantId; import static org.apache.commons.lang3.StringUtils.isNotBlank; import static org.springframework.http.ResponseEntity.created; import static org.springframework.http.ResponseEntity.ok; @@ -56,30 +54,23 @@ public class ServiceGroupController { private static final Logger log = LoggerFactory.getLogger(ServiceGroupController.class); @Autowired - ServiceGroupValidator serviceGroupValidator; - - @Autowired - private CaseSensitivityNormalizer caseSensitivityNormalizer; - - //TODO Migrate to Service (add one more level) - @Autowired - private DBMSDataManager dataManager; + private ServiceGroupValidator serviceGroupValidator; @Autowired private ServiceMetadataPathBuilder pathBuilder; @Autowired - private BaseServiceGroupInterfaceImpl serviceGroupService; + private ServiceGroupService serviceGroupService; @Autowired - private BaseServiceMetadataInterfaceImpl serviceMetadataService; + private ServiceMetadataService serviceMetadataService; @GetMapping(produces = "text/xml; charset=UTF-8") public ServiceGroup getServiceGroup(@PathVariable String serviceGroupId) { log.info("GET ServiceGrooup: {}", serviceGroupId); - ServiceGroup serviceGroup = serviceGroupService.getServiceGroup(serviceGroupId); + ServiceGroup serviceGroup = serviceGroupService.getServiceGroup(asParticipantId(serviceGroupId)); addReferences(serviceGroup); log.info("Finished GET ServiceGrooup: {}", serviceGroupId); @@ -103,7 +94,7 @@ public class ServiceGroupController { // Service action String newOwnerName = isNotBlank(serviceGroupOwner) ? serviceGroupOwner : SecurityContextHolder.getContext().getAuthentication().getName(); - boolean newServiceGroupCreated = dataManager.saveServiceGroup(serviceGroup, newOwnerName); + boolean newServiceGroupCreated = serviceGroupService.saveServiceGroup(serviceGroup, newOwnerName); log.info("Finished PUT ServiceGroup: {}", serviceGroupId); @@ -117,14 +108,14 @@ public class ServiceGroupController { log.info("DELETE ServiceGroup: {}", serviceGroupId); final ParticipantIdentifierType aServiceGroupID = Identifiers.asParticipantId(serviceGroupId); - dataManager.deleteServiceGroup(aServiceGroupID); + serviceGroupService.deleteServiceGroup(aServiceGroupID); log.info("Finished DELETE ServiceGroup: {}", serviceGroupId); } private void addReferences(ServiceGroup serviceGroup) { ParticipantIdentifierType participantId = serviceGroup.getParticipantIdentifier(); - List<DocumentIdentifier> docIds = serviceMetadataService.getMetadataIdentifiers(asString(participantId)); + List<DocumentIdentifier> docIds = serviceMetadataService.findServiceMetadataIdentifiers(participantId); List<ServiceMetadataReferenceType> referenceIds = serviceGroup.getServiceMetadataReferenceCollection().getServiceMetadataReferences(); for (DocumentIdentifier docId : docIds) { String url = pathBuilder.buildSelfUrl(participantId, docId); diff --git a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/controllers/ServiceMetadataController.java b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/controllers/ServiceMetadataController.java index 0c989655a5f4c1bcab5d7f2be2760671cb399cbf..eff5c3f27b58dd937df7b5422f378b19de92f1e4 100644 --- a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/controllers/ServiceMetadataController.java +++ b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/controllers/ServiceMetadataController.java @@ -16,10 +16,11 @@ package eu.europa.ec.edelivery.smp.controllers; import eu.europa.ec.cipa.smp.server.conversion.ServiceMetadataConverter; -import eu.europa.ec.cipa.smp.server.data.dbms.DBMSDataManager; -import eu.europa.ec.cipa.smp.server.services.BaseServiceMetadataInterfaceImpl; +import eu.europa.ec.edelivery.smp.services.ServiceMetadataService; import eu.europa.ec.edelivery.smp.validation.ServiceMetadataValidator; import eu.europa.ec.smp.api.exceptions.XmlInvalidAgainstSchemaException; +import org.oasis_open.docs.bdxr.ns.smp._2016._05.DocumentIdentifier; +import org.oasis_open.docs.bdxr.ns.smp._2016._05.ParticipantIdentifierType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -45,15 +46,11 @@ public class ServiceMetadataController { private static final Logger log = LoggerFactory.getLogger(ServiceMetadataController.class); - //TODO Migrate to Service (add one more level) @Autowired - private DBMSDataManager dataManager; + private ServiceMetadataValidator serviceMetadataValidator; @Autowired - ServiceMetadataValidator serviceMetadataValidator; - - @Autowired - private BaseServiceMetadataInterfaceImpl serviceMetadataService; + private ServiceMetadataService serviceMetadataService; @Autowired private ServiceMetadataPathBuilder pathBuilder; @@ -64,7 +61,7 @@ public class ServiceMetadataController { log.info("GET ServiceMetadata: {} - {}", serviceGroupId, serviceMetadataId); - Document serviceMetadata = serviceMetadataService.getServiceRegistration(serviceGroupId, serviceMetadataId); + Document serviceMetadata = serviceMetadataService.getServiceMetadataDocument(asParticipantId(serviceGroupId), asDocumentId(serviceMetadataId)); log.info("GET ServiceMetadata finished: {} - {}", serviceGroupId, serviceMetadataId); return ServiceMetadataConverter.toString(serviceMetadata); @@ -81,7 +78,7 @@ public class ServiceMetadataController { serviceMetadataValidator.validate(serviceGroupId, serviceMetadataId, body); - boolean newServiceMetadataCreated = dataManager.saveService(asParticipantId(serviceGroupId), asDocumentId(serviceMetadataId), body); + boolean newServiceMetadataCreated = serviceMetadataService.saveServiceMetadata(asParticipantId(serviceGroupId), asDocumentId(serviceMetadataId), body); log.info("PUT ServiceMetadata finished: {} - {}\n{}", serviceGroupId, serviceMetadataId, body); @@ -91,10 +88,10 @@ public class ServiceMetadataController { @DeleteMapping @PreAuthorize("hasAnyAuthority('ROLE_SMP_ADMIN', @caseSensitivityNormalizer.normalizeParticipantId(#serviceGroupId))") public ResponseEntity deleteServiceMetadata(@PathVariable String serviceGroupId, - @PathVariable String serviceMetadataId) { + @PathVariable String serviceMetadataId) { log.info("DELETE ServiceMetadata: {} - {}", serviceGroupId, serviceMetadataId); - dataManager.deleteService(asParticipantId(serviceGroupId), asDocumentId(serviceMetadataId)); + serviceMetadataService.deleteServiceMetadata(asParticipantId(serviceGroupId), asDocumentId(serviceMetadataId)); log.info("DELETE ServiceMetadata finished: {} - {}", serviceGroupId, serviceMetadataId); diff --git a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/controllers/ServiceMetadataPathBuilder.java b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/controllers/ServiceMetadataPathBuilder.java index 1af84fc7427db5e830da45697a52e4b96435d597..6d45c434c46d18c8dab52f343178f53a2b94cd68 100644 --- a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/controllers/ServiceMetadataPathBuilder.java +++ b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/controllers/ServiceMetadataPathBuilder.java @@ -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.controllers; import org.oasis_open.docs.bdxr.ns.smp._2016._05.DocumentIdentifier; diff --git a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/error/ErrorMappingControllerAdvice.java b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/error/ErrorMappingControllerAdvice.java index 8e042beb92d3077168a247d28581d494eb4d7d6c..f4fa2e6e4afaab25344c952b9fa10eeed194d79d 100644 --- a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/error/ErrorMappingControllerAdvice.java +++ b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/error/ErrorMappingControllerAdvice.java @@ -31,10 +31,10 @@ package eu.europa.ec.edelivery.smp.error; import ec.services.smp._1.ErrorResponse; -import eu.europa.ec.cipa.smp.server.errors.exceptions.CertificateAuthenticationException; -import eu.europa.ec.cipa.smp.server.errors.exceptions.NotFoundException; -import eu.europa.ec.cipa.smp.server.errors.exceptions.UnknownUserException; -import eu.europa.ec.cipa.smp.server.errors.exceptions.XmlParsingException; +import eu.europa.ec.edelivery.smp.exceptions.CertificateAuthenticationException; +import eu.europa.ec.edelivery.smp.exceptions.NotFoundException; +import eu.europa.ec.edelivery.smp.exceptions.UnknownUserException; +import eu.europa.ec.edelivery.smp.exceptions.XmlParsingException; import eu.europa.ec.edelivery.smp.error.exceptions.BadRequestException; import eu.europa.ec.smp.api.exceptions.MalformedIdentifierException; import eu.europa.ec.smp.api.exceptions.XmlInvalidAgainstSchemaException; diff --git a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/error/ErrorResponseBuilder.java b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/error/ErrorResponseBuilder.java index 3fe984bbf96330698a9799fc0e8126f4e9be4309..37184cf79296932d8e918cb785088be988e8722f 100644 --- a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/error/ErrorResponseBuilder.java +++ b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/error/ErrorResponseBuilder.java @@ -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.error; import ec.services.smp._1.ErrorResponse; @@ -54,18 +39,17 @@ public class ErrorResponseBuilder { private HttpStatus status = INTERNAL_SERVER_ERROR; private ErrorBusinessCode errorBusinessCode = TECHNICAL; private String strErrorDescription = "Unexpected technical error occurred."; - - private static final SimpleDateFormat TIMESTAMP_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSz"); + private static final String TIMESTAMP_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSz"; private static String getErrorUniqueId() { StringBuilder errId = new StringBuilder(); - errId.append(TIMESTAMP_FORMAT.format(new Date())) + errId.append(new SimpleDateFormat(TIMESTAMP_FORMAT).format(new Date())) .append(":") .append(UUID.randomUUID()); return String.valueOf(errId); } - public ErrorResponseBuilder(){} + public ErrorResponseBuilder() {} private ErrorResponseBuilder(HttpStatus status) { this.status = status; diff --git a/smp-webapp/src/main/webapp/WEB-INF/web.xml b/smp-webapp/src/main/webapp/WEB-INF/web.xml index 9c3a6ed4aada05a38315742aea17eee1aa53ed5c..f3c817509c849aa4ec9abdd84f825257c588d594 100644 --- a/smp-webapp/src/main/webapp/WEB-INF/web.xml +++ b/smp-webapp/src/main/webapp/WEB-INF/web.xml @@ -69,10 +69,6 @@ </listener> - <listener> - <listener-class>eu.europa.ec.cipa.smp.server.util.LogStartupListener</listener-class> - </listener> - <!-- SML handling: filter --> <filter> <filter-name>registrationhook</filter-name>