Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS has been phased out. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit 8099ce98 authored by Joze RIHTARSIC's avatar Joze RIHTARSIC
Browse files

- update ui entities for new database model

parent 696262cd
Branches
Tags
No related merge requests found
Showing
with 549 additions and 606 deletions
......@@ -24,7 +24,7 @@
<modules>
<module>smp-parent-pom</module>
<module>smp-api</module>
<module>smp-angular</module>
<!-- module>smp-angular</module -->
<module>smp-server-library</module>
<module>smp-webapp</module>
</modules>
......
......@@ -2,7 +2,7 @@ package eu.europa.ec.edelivery.smp;
public enum SMPRole {
SMP_ADMI,
SERVICEGROUP_ADMIN,
SMP_ADMIN,
SERVICE_GROUP_ADMIN,
SYSTEM_ADMIN
}
......@@ -14,19 +14,40 @@
package eu.europa.ec.edelivery.smp.data.dao;
import eu.europa.ec.edelivery.smp.data.model.BaseEntity;
import eu.europa.ec.edelivery.smp.logging.SMPLogger;
import eu.europa.ec.edelivery.smp.logging.SMPLoggerFactory;
import eu.europa.ec.edelivery.smp.services.ServiceGroupService;
import org.springframework.core.GenericTypeResolver;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import javax.transaction.Transactional;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* Created by gutowpa on 24/11/2017.
* Database abstract resource file. Class implements all common methods for all resources.
*
* @author Joze Rihtarsic
* @since 4.1
*/
public abstract class BaseDao<E extends BaseEntity> {
private static final SMPLogger LOG = SMPLoggerFactory.getLogger(ServiceGroupService.class);
@PersistenceContext
protected EntityManager em;
protected EntityManager memEManager;
private final Class<E> entityClass;
......@@ -35,22 +56,32 @@ public abstract class BaseDao<E extends BaseEntity> {
}
public E find(Object primaryKey) {
return em.find(entityClass, primaryKey);
return memEManager.find(entityClass, primaryKey);
}
/**
* save or update database entity
*
* @param entity
*/
@Transactional
public void persistFlushDetach(E entity) {
em.persist(entity);
em.flush();
em.detach(entity);
memEManager.persist(entity);
memEManager.flush();
memEManager.detach(entity);
}
/**
* save or update detached database entity
*
* @param entity
*/
@Transactional
public void update(E entity) {
em.merge(entity);
em.flush();
em.detach(entity);
memEManager.merge(entity);
memEManager.flush();
memEManager.detach(entity);
}
......@@ -58,11 +89,11 @@ public abstract class BaseDao<E extends BaseEntity> {
* 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
* False if entity does not exist, so nothing was changed
*/
@Transactional
public boolean removeById(Object primaryKey) {
int removedRecords = em.createQuery("delete from " + entityClass.getName() + " e where e.id = :primaryKey")
int removedRecords = memEManager.createQuery("delete from " + entityClass.getName() + " e where e.id = :primaryKey")
.setParameter("primaryKey", primaryKey)
.executeUpdate();
return removedRecords > 0;
......@@ -77,7 +108,196 @@ public abstract class BaseDao<E extends BaseEntity> {
*
*/
public void clearPersistenceContext(){
em.clear();
memEManager.clear();
}
/**
* Method generates CriteriaQuery for search or count. If filter property value should match multiple values eg: column in (:list)
* than filter method must end with List and returned value must be list. If property is comparable (decimal, int, date)
* if filter method ends with From, than predicate greaterThanOrEqualTo is set to quer. If Method end To, than
* predicate cb.lessThan is setted. If filter property has null value, than filter parameter is ignored.
*
* @param searchParams
* @param forCount
* @param sortField
* @param sortOrder
* @return
*/
protected < D> CriteriaQuery createSearchCriteria(Object searchParams, Class<D> filterType,
boolean forCount, String sortField, String sortOrder) {
CriteriaBuilder cb = memEManager.getCriteriaBuilder();
CriteriaQuery cq = forCount ? cb.createQuery(Long.class
) : cb.createQuery(entityClass);
Root<E> om = cq.from(filterType == null ? entityClass : filterType);
if (forCount) {
cq.select(cb.count(om));
} else if (sortField != null) {
if (sortOrder != null && sortOrder.equalsIgnoreCase("desc")) {
cq.orderBy(cb.asc(om.get(sortField)));
} else {
cq.orderBy(cb.desc(om.get(sortField)));
}
} else {
// cq.orderBy(cb.desc(om.get("Id")));
}
List<Predicate> lstPredicate = new ArrayList<>();
// set order by
if (searchParams != null) {
Class cls = searchParams.getClass();
Method[] methodList = cls.getMethods();
for (Method m : methodList) {
// only getters (public, starts with get, no arguments)
String mName = m.getName();
if (Modifier.isPublic(m.getModifiers()) && m.getParameterCount() == 0
&& !m.getReturnType().equals(Void.TYPE)
&& (mName.startsWith("get") || mName.startsWith("is"))) {
String fieldName = mName.substring(mName.startsWith("get") ? 3 : 2);
// get retur parameter
Object searchValue;
try {
searchValue = m.invoke(searchParams, new Object[]{});
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
// LOG.error(l, ex);
continue;
}
if (searchValue == null) {
continue;
}
if (fieldName.endsWith("List") && searchValue instanceof List) {
String property = fieldName.substring(0, fieldName.lastIndexOf(
"List"));
if (!((List) searchValue).isEmpty()) {
lstPredicate.add(om.get(property).in(
((List) searchValue).toArray()));
} else {
lstPredicate.add(om.get(property).isNull());
}
} else {
try {
cls.getMethod("set" + fieldName, new Class[]{m.getReturnType()});
} catch (NoSuchMethodException | SecurityException ex) {
// method does not have setter // ignore other methods
continue;
}
if (fieldName.endsWith("From") && searchValue instanceof Comparable) {
lstPredicate.add(cb.greaterThanOrEqualTo(
om.get(fieldName.substring(0, fieldName.
lastIndexOf("From"))),
(Comparable) searchValue));
} else if (fieldName.endsWith("To") && searchValue instanceof Comparable) {
lstPredicate.add(cb.lessThan(
om.
get(fieldName.substring(0, fieldName.lastIndexOf(
"To"))),
(Comparable) searchValue));
} else if (searchValue instanceof String) {
if (!((String) searchValue).isEmpty()) {
lstPredicate.add(cb.equal(om.get(fieldName), searchValue));
}
} else if (searchValue instanceof BigInteger) {
lstPredicate.add(cb.equal(om.get(fieldName), searchValue));
} else {
LOG.warn("Unknown search value type %s for method %s! "
+ "Parameter is ignored!",
searchValue, fieldName);
}
}
}
}
if (!lstPredicate.isEmpty()) {
Predicate[] tblPredicate = lstPredicate.stream().toArray(
Predicate[]::new);
cq.where(cb.and(tblPredicate));
}
}
return cq;
}
/**
* Method returns paginated entity list with give pagination parameters and filters.
* Filter methods must match object methods. If property value should match multiple values eg: column in (:list)
* than filter method must end with List and returned value must be list. If property is comparable (decimal, int, date)
* if filter method ends with From, than predicate greaterThanOrEqualTo is set to quer. If Method end To, than
* predicate cb.lessThan is setted. If filter property has null value, than filter parameter is ignored.
*
* @param startingAt
* @param maxResultCnt
* @param sortField
* @param sortOrder
* @param filters
* @return List
*/
public List<E> getDataList(int startingAt, int maxResultCnt,
String sortField,
String sortOrder, Object filters) {
return getDataList(startingAt, maxResultCnt, sortField, sortOrder,
filters, null);
}
/**
* Method returns paginated entity list with give pagination parameters and filters.
* Filter methods must match object methods. If property value should match multiple values eg: column in (:list)
* than filter method must end with List and returned value must be list. If property is comparable (decimal, int, date)
* if filter method ends with From, than predicate greaterThanOrEqualTo is set to quer. If Method end To, than
* predicate cb.lessThan is setted. If filter property has null value, than filter parameter is ignored.
*
* @param startingAt
* @param maxResultCnt
* @param sortField
* @param sortOrder
* @param filters
* @param filterType
* @return List
*/
public <D> List<E> getDataList(int startingAt,
int maxResultCnt,
String sortField,
String sortOrder, Object filters, Class<D> filterType) {
List<E> lstResult;
try {
CriteriaQuery<E> cq = createSearchCriteria(filters, filterType,
false, sortField,
sortOrder);
TypedQuery<E> q = memEManager.createQuery(cq);
if (maxResultCnt > 0) {
q.setMaxResults(maxResultCnt);
}
if (startingAt > 0) {
q.setFirstResult(startingAt);
}
lstResult = q.getResultList();
} catch (NoResultException ex) {
lstResult = new ArrayList<>();
}
return lstResult;
}
/**
* Method returns filtered list count.
* Filter methods must match object methods. If property value should match multiple values eg: column in (:list)
* than filter method must end with List and returned value must be list. If property is comparable (decimal, int, date)
* if filter method ends with From, than predicate greaterThanOrEqualTo is set to quer. If Method end To, than
* predicate cb.lessThan is setted. If filter property has null value, than filter parameter is ignored.
* @param filters
* @return
*/
public long getDataListCount(Object filters) {
CriteriaQuery<Long> cqCount = createSearchCriteria(filters, null, true,
null,
null);
Long res = memEManager.createQuery(cqCount).getSingleResult();
return res;
}
......
......@@ -42,7 +42,7 @@ public class DomainDao extends BaseDao<DBDomain> {
public Optional<DBDomain> getTheOnlyDomain() {
try {
// expected is only one domain,
TypedQuery<DBDomain> query = em.createNamedQuery("DBDomain.getAll", DBDomain.class);
TypedQuery<DBDomain> query = memEManager.createNamedQuery("DBDomain.getAll", DBDomain.class);
return Optional.of(query.getSingleResult());
} catch (NonUniqueResultException e) {
return Optional.empty();
......@@ -58,7 +58,7 @@ public class DomainDao extends BaseDao<DBDomain> {
* @throws IllegalStateException if no domain is configured
*/
public List<DBDomain> getAllDomains() {
TypedQuery<DBDomain> query = em.createNamedQuery("DBDomain.getAll", DBDomain.class);
TypedQuery<DBDomain> query = memEManager.createNamedQuery("DBDomain.getAll", DBDomain.class);
return query.getResultList();
}
......@@ -71,7 +71,7 @@ public class DomainDao extends BaseDao<DBDomain> {
*/
public Optional<DBDomain> getDomainByCode(String domainCode) {
try {
TypedQuery<DBDomain> query = em.createNamedQuery("DBDomain.getDomainByCode", DBDomain.class);
TypedQuery<DBDomain> query = memEManager.createNamedQuery("DBDomain.getDomainByCode", DBDomain.class);
query.setParameter("domainCode", domainCode);
return Optional.of(query.getSingleResult());
} catch (NoResultException e) {
......@@ -89,7 +89,7 @@ public class DomainDao extends BaseDao<DBDomain> {
*/
@Transactional
public boolean removeByDomainCode(String code) {
int removedRecords = em.createNamedQuery("DBDomain.removeByDomainCode")
int removedRecords = memEManager.createNamedQuery("DBDomain.removeByDomainCode")
.setParameter("domainCode", code)
.executeUpdate();
return removedRecords > 0;
......
......@@ -42,7 +42,7 @@ public class ServiceGroupDao extends BaseDao<DBServiceGroup> {
try {
TypedQuery<DBServiceGroup> query = em.createNamedQuery("DBServiceGroup.getServiceGroup", DBServiceGroup.class);
TypedQuery<DBServiceGroup> query = memEManager.createNamedQuery("DBServiceGroup.getServiceGroup", DBServiceGroup.class);
query.setParameter("participantIdentifier", participantId);
query.setParameter("participantScheme", schema);
DBServiceGroup res = query.getSingleResult();
......@@ -78,7 +78,7 @@ public class ServiceGroupDao extends BaseDao<DBServiceGroup> {
em.createNamedQuery("DBServiceGroup.deleteById")
.setParameter("id", dbServiceGroup.getId()).executeUpdate()>0;
*/
em.remove(em.contains(dbServiceGroup) ? dbServiceGroup : em.merge(dbServiceGroup));
memEManager.remove(memEManager.contains(dbServiceGroup) ? dbServiceGroup : memEManager.merge(dbServiceGroup));
}
......
......@@ -46,7 +46,7 @@ public class ServiceMetadataDao extends BaseDao<DBServiceMetadata> {
public Optional<DBServiceMetadata> findServiceMetadata(String participantId, String participantSchema, String documentId, String documentSchema){
try {
TypedQuery<DBServiceMetadata> query = em.createNamedQuery("DBServiceMetadata.getBySGIdentifierAndSMDdentifier", DBServiceMetadata.class);
TypedQuery<DBServiceMetadata> query = memEManager.createNamedQuery("DBServiceMetadata.getBySGIdentifierAndSMDdentifier", DBServiceMetadata.class);
query.setParameter("partcId", participantId);
query.setParameter("partcSch", participantSchema);
query.setParameter("docId", documentId);
......@@ -62,7 +62,7 @@ public class ServiceMetadataDao extends BaseDao<DBServiceMetadata> {
public List<DBServiceMetadata> getAllMetadataForServiceGroup(String participantId,
String participantSchema) {
TypedQuery<DBServiceMetadata> query = em.createNamedQuery("DBServiceMetadata.getBySGIdentifier", DBServiceMetadata.class);
TypedQuery<DBServiceMetadata> query = memEManager.createNamedQuery("DBServiceMetadata.getBySGIdentifier", DBServiceMetadata.class);
query.setParameter("partcId", participantId);
query.setParameter("partcSch", participantSchema);
return query.getResultList();
......
......@@ -44,7 +44,7 @@ public class UserDao extends BaseDao<DBUser> {
// all users are SERVICEGROUP_ADMIN
lstRes.add(DBUserAuthority.S_ROLE_SERVICEGROUP_ADMIN);
List<DBUserAuthority> lst = em
List<DBUserAuthority> lst = memEManager
.createNamedQuery("DBUserAuthority.getRolesForUsernameNativeQuery")
.setParameter( "username",username)
.getResultList();
......@@ -98,7 +98,7 @@ public class UserDao extends BaseDao<DBUser> {
return Optional.empty();
}
try {
TypedQuery<DBUser> query = em.createNamedQuery("DBUser.getUserByUsernameInsensitive", DBUser.class);
TypedQuery<DBUser> query = memEManager.createNamedQuery("DBUser.getUserByUsernameInsensitive", DBUser.class);
query.setParameter("username", username.trim());
return Optional.of(query.getSingleResult());
} catch (NoResultException e) {
......@@ -116,7 +116,7 @@ public class UserDao extends BaseDao<DBUser> {
*/
public Optional<DBUser> findUserByCertificateId(String certificateId) {
try {
TypedQuery<DBUser> query = em.createNamedQuery("DBUser.getUserByCertificateId", DBUser.class);
TypedQuery<DBUser> query = memEManager.createNamedQuery("DBUser.getUserByCertificateId", DBUser.class);
query.setParameter("certificateId", certificateId);
return Optional.of(query.getSingleResult());
} catch (NoResultException e) {
......
package eu.europa.ec.edelivery.smp.data.dao.ui;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Service
public class UiDaoService {
@PersistenceContext
protected EntityManager memEManager;
private static final Logger LOG = LoggerFactory.getLogger(UiDaoService.class);
/**
*
* @param <T>
* @param type
* @param searchParams
* @param forCount
* @param sortField
* @param sortOrder
* @return
*/
protected <T, D> CriteriaQuery createSearchCriteria(Class<T> type,
Object searchParams, Class<D> filterType,
boolean forCount, String sortField, String sortOrder) {
CriteriaBuilder cb = memEManager.getCriteriaBuilder();
CriteriaQuery cq = forCount ? cb.createQuery(Long.class
) : cb.createQuery(
type);
Root<T> om = cq.from(filterType == null ? type : filterType);
if (forCount) {
cq.select(cb.count(om));
} else if (sortField != null) {
if (sortOrder != null && sortOrder.equalsIgnoreCase("desc")) {
cq.orderBy(cb.asc(om.get(sortField)));
} else {
cq.orderBy(cb.desc(om.get(sortField)));
}
} else {
// cq.orderBy(cb.desc(om.get("Id")));
}
List<Predicate> lstPredicate = new ArrayList<>();
// set order by
if (searchParams != null) {
Class cls = searchParams.getClass();
Method[] methodList = cls.getMethods();
for (Method m : methodList) {
// only getters (public, starts with get, no arguments)
String mName = m.getName();
if (Modifier.isPublic(m.getModifiers()) && m.getParameterCount() == 0
&& !m.getReturnType().equals(Void.TYPE)
&& (mName.startsWith("get") || mName.startsWith("is"))) {
String fieldName = mName.substring(mName.startsWith("get") ? 3 : 2);
// get returm parameter
Object searchValue;
try {
searchValue = m.invoke(searchParams, new Object[]{});
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
// LOG.error(l, ex);
continue;
}
if (searchValue == null) {
continue;
}
if (fieldName.endsWith("List") && searchValue instanceof List) {
String property = fieldName.substring(0, fieldName.lastIndexOf(
"List"));
if (!((List) searchValue).isEmpty()) {
lstPredicate.add(om.get(property).in(
((List) searchValue).toArray()));
} else {
lstPredicate.add(om.get(property).isNull());
}
} else {
try {
cls.getMethod("set" + fieldName, new Class[]{m.getReturnType()});
} catch (NoSuchMethodException | SecurityException ex) {
// method does not have setter // ignore other methods
continue;
}
if (fieldName.endsWith("From") && searchValue instanceof Comparable) {
lstPredicate.add(cb.greaterThanOrEqualTo(
om.get(fieldName.substring(0, fieldName.
lastIndexOf("From"))),
(Comparable) searchValue));
} else if (fieldName.endsWith("To") && searchValue instanceof Comparable) {
lstPredicate.add(cb.lessThan(
om.
get(fieldName.substring(0, fieldName.lastIndexOf(
"To"))),
(Comparable) searchValue));
} else if (searchValue instanceof String) {
if (!((String) searchValue).isEmpty()) {
lstPredicate.add(cb.equal(om.get(fieldName), searchValue));
}
} else if (searchValue instanceof BigInteger) {
lstPredicate.add(cb.equal(om.get(fieldName), searchValue));
} else {
LOG.warn("Unknown search value type %s for method %s! "
+ "Parameter is ignored!",
searchValue, fieldName);
}
}
}
}
if (!lstPredicate.isEmpty()) {
Predicate[] tblPredicate = lstPredicate.stream().toArray(
Predicate[]::new);
cq.where(cb.and(tblPredicate));
}
}
return cq;
}
public <T> List<T> getDataList(Class<T> type, String hql,
Map<String, Object> params) {
TypedQuery<T> q = memEManager.createQuery(hql, type);
params.forEach((param, value) -> {
q.setParameter(param, value);
});
return q.getResultList();
}
/**
*
* @param <T>
* @param type
* @param startingAt
* @param maxResultCnt
* @param sortField
* @param sortOrder
* @param filters
* @return
*/
public <T> List<T> getDataList(Class<T> type, int startingAt, int maxResultCnt,
String sortField,
String sortOrder, Object filters) {
return getDataList(type, startingAt, maxResultCnt, sortField, sortOrder,
filters, null);
}
/**
*
* @param <T>
* @param resultType
* @param startingAt
* @param maxResultCnt
* @param sortField
* @param sortOrder
* @param filters
* @param filterType
* @return
*/
public <T, D> List<T> getDataList(Class<T> resultType, int startingAt,
int maxResultCnt,
String sortField,
String sortOrder, Object filters, Class<D> filterType) {
List<T> lstResult;
try {
CriteriaQuery<T> cq = createSearchCriteria(resultType, filters, filterType,
false, sortField,
sortOrder);
TypedQuery<T> q = memEManager.createQuery(cq);
if (maxResultCnt > 0) {
q.setMaxResults(maxResultCnt);
}
if (startingAt > 0) {
q.setFirstResult(startingAt);
}
lstResult = q.getResultList();
} catch (NoResultException ex) {
lstResult = new ArrayList<>();
}
return lstResult;
}
/**
*
* @param <T>
* @param type
* @param filters
* @return
*/
public <T> long getDataListCount(Class<T> type, Object filters) {
CriteriaQuery<Long> cqCount = createSearchCriteria(type, filters, null, true,
null,
null);
Long res = memEManager.createQuery(cqCount).getSingleResult();
return res;
}
public <T> void persist(T entity){
memEManager.persist(entity);
}
public <T> void update(T entity){
memEManager.merge(entity);
}
public <T> void remove(T entity){
memEManager.remove(entity);
}
}
......@@ -10,89 +10,88 @@ import java.util.Objects;
* @since 4.1
*/
@Entity
@Table(name = "smp_domain")
public class DomainRO implements Serializable {
private static final long serialVersionUID = -9008583888835630560L;
@Id
@Column(name = "domainId")
private String domainId;
@Column(name = "bdmslClientCertHeader")
private String bdmslClientCertHeader;
@Column(name = "bdmslClientCertAlias")
private String bdmslClientCertAlias;
@Column(name = "bdmslSmpId")
private String bdmslSmpId;
@Column(name = "signatureCertAlias")
private String signatureCertAlias;
Long id;
String domainCode;
String smlSubdomain;
String smlSmpId;
String smlParticipantIdentifierRegExp;
String smlClientCertHeader;
String smlClientKeyAlias;
String signatureKeyAlias;
;
public DomainRO() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getDomainCode() {
return domainCode;
}
public DomainRO(String domainId, String bdmslClientCertHeader, String bdmslClientCertAlias, String bdmslSmpId, String signatureCertAlias) {
this.domainId = domainId;
this.bdmslClientCertHeader = bdmslClientCertHeader;
this.bdmslClientCertAlias = bdmslClientCertAlias;
this.bdmslSmpId = bdmslSmpId;
this.signatureCertAlias = signatureCertAlias;
public void setDomainCode(String domainCode) {
this.domainCode = domainCode;
}
public String getDomainId() {
return domainId;
public String getSmlSubdomain() {
return smlSubdomain;
}
public void setDomainId(String domainId) {
this.domainId = domainId;
public void setSmlSubdomain(String smlSubdomain) {
this.smlSubdomain = smlSubdomain;
}
public String getBdmslClientCertHeader() {
return bdmslClientCertHeader;
public String getSmlSmpId() {
return smlSmpId;
}
public void setBdmslClientCertHeader(String bdmslClientCertHeader) {
this.bdmslClientCertHeader = bdmslClientCertHeader;
public void setSmlSmpId(String smlSmpId) {
this.smlSmpId = smlSmpId;
}
public String getBdmslClientCertAlias() {
return bdmslClientCertAlias;
public String getSmlParticipantIdentifierRegExp() {
return smlParticipantIdentifierRegExp;
}
public void setBdmslClientCertAlias(String bdmslClientCertAlias) {
this.bdmslClientCertAlias = bdmslClientCertAlias;
public void setSmlParticipantIdentifierRegExp(String smlParticipantIdentifierRegExp) {
this.smlParticipantIdentifierRegExp = smlParticipantIdentifierRegExp;
}
public String getBdmslSmpId() {
return bdmslSmpId;
public String getSmlClientCertHeader() {
return smlClientCertHeader;
}
public void setBdmslSmpId(String bdmslSmpId) {
this.bdmslSmpId = bdmslSmpId;
public void setSmlClientCertHeader(String smlClientCertHeader) {
this.smlClientCertHeader = smlClientCertHeader;
}
public String getSignatureCertAlias() {
return signatureCertAlias;
public String getSmlClientKeyAlias() {
return smlClientKeyAlias;
}
public void setSignatureCertAlias(String signatureCertAlias) {
this.signatureCertAlias = signatureCertAlias;
public void setSmlClientKeyAlias(String smlClientKeyAlias) {
this.smlClientKeyAlias = smlClientKeyAlias;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
DomainRO domainRO = (DomainRO) o;
return Objects.equals(domainId, domainRO.domainId) &&
Objects.equals(bdmslSmpId, domainRO.bdmslSmpId);
public String getSignatureKeyAlias() {
return signatureKeyAlias;
}
@Override
public int hashCode() {
return Objects.hash(domainId, bdmslSmpId);
public void setSignatureKeyAlias(String signatureKeyAlias) {
this.signatureKeyAlias = signatureKeyAlias;
}
}
......@@ -13,25 +13,18 @@ import java.util.Objects;
* @since 4.1
*/
@Entity
@Table(name = "smp_service_group")
public class ServiceGroupRO implements Serializable {
private static final long serialVersionUID = -7523221767041516157L;
@EmbeddedId
ServiceGroupROId serviceGroupROId;
private String participantIdentifier;
private String participantScheme;
private boolean smlRegistered = false;
@Column(name = "domainId")
private String domain;
public ServiceGroupROId getServiceGroupROId() {
return serviceGroupROId;
}
private String domain;
public void setServiceGroupROId(ServiceGroupROId serviceGroupROId) {
this.serviceGroupROId = serviceGroupROId;
}
public String getDomain() {
return domain;
......@@ -41,68 +34,27 @@ public class ServiceGroupRO implements Serializable {
this.domain = domain;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ServiceGroupRO that = (ServiceGroupRO) o;
return Objects.equals(serviceGroupROId, that.serviceGroupROId);
}
@Override
public int hashCode() {
return Objects.hash(serviceGroupROId);
}
@Embeddable
public static class ServiceGroupROId implements Serializable {
private static final long serialVersionUID = 7895751676689305736L;
@Column(name = "businessIdentifier")
private String participantId;
@Column(name = "businessIdentifierScheme")
private String participantSchema;
public ServiceGroupROId(){
}
public ServiceGroupROId(String participantId, String participantSchema) {
this.participantId = participantId;
this.participantSchema = participantSchema;
}
public String getParticipantId() {
return participantId;
public String getParticipantIdentifier() {
return participantIdentifier;
}
public void setParticipantId(String participantId) {
this.participantId = participantId;
public void setParticipantIdentifier(String participantIdentifier) {
this.participantIdentifier = participantIdentifier;
}
public String getParticipantSchema() {
return participantSchema;
public String getParticipantScheme() {
return participantScheme;
}
public void setParticipantSchema(String participanSchema) {
this.participantSchema = participanSchema;
public void setParticipantScheme(String participantScheme) {
this.participantScheme = participantScheme;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ServiceGroupROId that = (ServiceGroupROId) o;
return Objects.equals(participantId, that.participantId) &&
Objects.equals(participantSchema, that.participantSchema);
public boolean isSmlRegistered() {
return smlRegistered;
}
@Override
public int hashCode() {
return Objects.hash(participantId, participantSchema);
}
public void setSmlRegistered(boolean smlRegistered) {
this.smlRegistered = smlRegistered;
}
}
......@@ -13,44 +13,16 @@ import java.util.Objects;
* @since 4.1
*/
@Entity
@Table(name = "smp_service_metadata")
public class ServiceMetadataRO implements Serializable {
private static final long serialVersionUID = 67944640449327185L;
@EmbeddedId
ServiceMetadataROId serviceMetadataROId;
public ServiceMetadataROId getServiceMetadataROId() {
return serviceMetadataROId;
}
public void setServiceMetadataROId(ServiceMetadataROId serviceMetadataROId) {
this.serviceMetadataROId = serviceMetadataROId;
}
@Embeddable
public static class ServiceMetadataROId implements Serializable {
private static final long serialVersionUID = -123975468926638078L;
@Column(name = "businessIdentifier")
private String participantId;
@Column(name = "businessIdentifierScheme")
private String participantSchema;
@Column(name = "documentIdentifierScheme")
private String documentIdScheme;
@Column(name = "documentIdentifier")
private String documentIdValue;
public ServiceMetadataROId() {
}
public ServiceMetadataROId(String participantId, String participantSchema, String documentIdScheme, String documentIdValue) {
this.participantId = participantId;
this.participantSchema = participantSchema;
this.documentIdScheme = documentIdScheme;
this.documentIdValue = documentIdValue;
}
public String getParticipantId() {
return participantId;
......@@ -84,20 +56,4 @@ public class ServiceMetadataRO implements Serializable {
this.documentIdValue = documentIdValue;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ServiceMetadataROId that = (ServiceMetadataROId) o;
return Objects.equals(participantId, that.participantId) &&
Objects.equals(participantSchema, that.participantSchema) &&
Objects.equals(documentIdScheme, that.documentIdScheme) &&
Objects.equals(documentIdValue, that.documentIdValue);
}
@Override
public int hashCode() {
return Objects.hash(participantId, participantSchema, documentIdScheme, documentIdValue);
}
}
}
package eu.europa.ec.edelivery.smp.data.ui;
import eu.europa.ec.edelivery.smp.data.model.CommonColumnsLengths;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Objects;
import static eu.europa.ec.edelivery.smp.data.model.CommonColumnsLengths.MAX_USERNAME_LENGTH;
......@@ -14,30 +16,21 @@ import static eu.europa.ec.edelivery.smp.data.model.CommonColumnsLengths.MAX_USE
* @author Joze Rihtarsic
* @since 4.1
*/
@Entity
@Table(name = "smp_user")
public class UserRO implements Serializable {
private static final long serialVersionUID = -4971552086560325302L;
@Id
@Column(name = "username")
private String username;
@Column(name = "password")
private String password;
@Column(name = "isadmin")
private boolean isAdmin;
private String email;
LocalDateTime passwordChanged;
private boolean active = true;
private String role;
public UserRO(){
}
public UserRO(String username, String password, boolean isAdmin) {
this.username = username;
this.password = password;
this.isAdmin = isAdmin;
}
public String getUsername() {
return username;
......@@ -55,25 +48,35 @@ public class UserRO implements Serializable {
this.password = password;
}
public boolean isAdmin() {
return isAdmin;
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public void setAdmin(boolean admin) {
isAdmin = admin;
public LocalDateTime getPasswordChanged() {
return passwordChanged;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
UserRO userRO = (UserRO) o;
return Objects.equals(username, userRO.username);
public void setPasswordChanged(LocalDateTime passwordChanged) {
this.passwordChanged = passwordChanged;
}
@Override
public int hashCode() {
public boolean isActive() {
return active;
}
public void setActive(boolean active) {
this.active = active;
}
public String getRole() {
return role;
}
return Objects.hash(username);
public void setRole(String role) {
this.role = role;
}
}
......@@ -9,52 +9,56 @@ package eu.europa.ec.edelivery.smp.exceptions;
*/
public enum ErrorCode {
INVALID_ENCODING ("SMP:100",ErrorBusinessCode.TECHNICAL, "Unsupported or invalid encoding for %s!"),
INVALID_ENCODING (500, "SMP:100",ErrorBusinessCode.TECHNICAL, "Unsupported or invalid encoding for %s!"),
// domain error
NO_DOMAIN ("SMP:110",ErrorBusinessCode.TECHNICAL, "No domain configured on SMP, at least one domain is mandatory!"),
DOMAIN_NOT_EXISTS("SMP:111",ErrorBusinessCode.NOT_FOUND, "Invalid domain '%s'!"),
INVALID_DOMAIN_CODE("SMP:112",ErrorBusinessCode.FORMAT_ERROR,"Provided Domain Code '%s' does not match required pattern: '%s'"),
ILLEGAL_STATE_DOMAIN_MULTIPLE_ENTRY("SMP:113",ErrorBusinessCode.TECHNICAL,"More than one domain entry (domain: '%s') is defined in database!"),
MISSING_DOMAIN("SMP:114",ErrorBusinessCode.MISSING_FIELD,"More than one domain registred on SMP. The domain must be defined!"),
NO_DOMAIN (500,"SMP:110",ErrorBusinessCode.TECHNICAL, "No domain configured on SMP, at least one domain is mandatory!"),
DOMAIN_NOT_EXISTS(404,"SMP:111",ErrorBusinessCode.NOT_FOUND, "Invalid domain '%s'!"),
INVALID_DOMAIN_CODE(400,"SMP:112",ErrorBusinessCode.FORMAT_ERROR,"Provided Domain Code '%s' does not match required pattern: '%s'"),
ILLEGAL_STATE_DOMAIN_MULTIPLE_ENTRY(500,"SMP:113",ErrorBusinessCode.TECHNICAL,"More than one domain entry (domain: '%s') is defined in database!"),
MISSING_DOMAIN(400,"SMP:114",ErrorBusinessCode.MISSING_FIELD,"More than one domain registred on SMP. The domain must be defined!"),
// user error messages
INVALID_USER_NO_IDENTIFIERS ("SMP:120",ErrorBusinessCode.MISSING_FIELD,"Invalid user - no identifiers!"),
ILLEGAL_STATE_USERNAME_MULTIPLE_ENTRY("SMP:121",ErrorBusinessCode.TECHNICAL,"More than one user entry (username: '%s') is defined in database!"),
ILLEGAL_STATE_CERT_ID_MULTIPLE_ENTRY("SMP:122",ErrorBusinessCode.TECHNICAL,"More than one certificate entry (cert. id: '%s') is defined in database!"),
USER_NOT_EXISTS("SMP:123",ErrorBusinessCode.NOT_FOUND,"User not exists or wrong password!"), // OWASP recommendation\
USER_IS_NOT_OWNER("SMP:124",ErrorBusinessCode.UNAUTHORIZED,"User %s is not owner of service group (part. id: %s, part. sch.: '%s')!"), // OWASP recommendation
INVALID_USER_NO_IDENTIFIERS (400,"SMP:120",ErrorBusinessCode.MISSING_FIELD,"Invalid user - no identifiers!"),
ILLEGAL_STATE_USERNAME_MULTIPLE_ENTRY(500,"SMP:121",ErrorBusinessCode.TECHNICAL,"More than one user entry (username: '%s') is defined in database!"),
ILLEGAL_STATE_CERT_ID_MULTIPLE_ENTRY(504,"SMP:122",ErrorBusinessCode.TECHNICAL,"More than one certificate entry (cert. id: '%s') is defined in database!"),
USER_NOT_EXISTS(404,"SMP:123",ErrorBusinessCode.NOT_FOUND,"User not exists or wrong password!"), // OWASP recommendation\
USER_IS_NOT_OWNER(400,"SMP:124",ErrorBusinessCode.UNAUTHORIZED,"User %s is not owner of service group (part. id: %s, part. sch.: '%s')!"), // OWASP recommendation
// service group error
ILLEGAL_STATE_SG_MULTIPLE_ENTRY ("SMP:130",ErrorBusinessCode.TECHNICAL,"More than one service group ( part. id: %s, part. sch.: '%s') is defined in database!"),
SG_NOT_EXISTS("SMP:131",ErrorBusinessCode.NOT_FOUND,"Service group not exists (dpart. id: '%s', part. sch.: '%s')!"),
SG_NOT_REGISTRED_FOR_DOMAIN("SMP:131",ErrorBusinessCode.NOT_FOUND,"Service group not registred for domain (domain: %s, part. id:~ '%s', part. sch.: '%s')!"),
INVALID_EXTENSION_FOR_SG ("SMP:132",ErrorBusinessCode.XML_INVALID,"Invalid extension for service group (part. id: '%s', part. sch.: '%s'). Error: %s!"),
ILLEGAL_STATE_SG_MULTIPLE_ENTRY (500,"SMP:130",ErrorBusinessCode.TECHNICAL,"More than one service group ( part. id: %s, part. sch.: '%s') is defined in database!"),
SG_NOT_EXISTS(404,"SMP:131",ErrorBusinessCode.NOT_FOUND,"Service group not exists (dpart. id: '%s', part. sch.: '%s')!"),
SG_NOT_REGISTRED_FOR_DOMAIN(400,"SMP:131",ErrorBusinessCode.NOT_FOUND,"Service group not registred for domain (domain: %s, part. id:~ '%s', part. sch.: '%s')!"),
INVALID_EXTENSION_FOR_SG (400,"SMP:132",ErrorBusinessCode.XML_INVALID,"Invalid extension for service group (part. id: '%s', part. sch.: '%s'). Error: %s!"),
// service metadata error
ILLEGAL_STATE_SMD_MULTIPLE_ENTRY ("SMP:140",ErrorBusinessCode.TECHNICAL,"More than one service metadata ( doc. id: %s, doc. sch.: '%s') for participant ( part. id %s, part. sch. : '%s') is defined in database!"),
METADATA_NOT_EXISTS("SMP:141",ErrorBusinessCode.NOT_FOUND,"ServiceMetadata not exist(part. id: '%s', part. sch.: '%s',doc. id: '%s', doc. sch.: '%s')!"),
SMD_NOT_EXISTS_FOR_DOMAIN("SMP:142",ErrorBusinessCode.NOT_FOUND,"ServiceMetadata not exists for domain (domain: %s, part. id: '%s', part. sch.: '%s')!"),
INVALID_SMD_XML ("SMP:143",ErrorBusinessCode.XML_INVALID,"Invalid service metada. Error: %s"),
ILLEGAL_STATE_SMD_MULTIPLE_ENTRY (500,"SMP:140",ErrorBusinessCode.TECHNICAL,"More than one service metadata ( doc. id: %s, doc. sch.: '%s') for participant ( part. id %s, part. sch. : '%s') is defined in database!"),
METADATA_NOT_EXISTS(404,"SMP:141",ErrorBusinessCode.NOT_FOUND,"ServiceMetadata not exist(part. id: '%s', part. sch.: '%s',doc. id: '%s', doc. sch.: '%s')!"),
SMD_NOT_EXISTS_FOR_DOMAIN(404,"SMP:142",ErrorBusinessCode.NOT_FOUND,"ServiceMetadata not exists for domain (domain: %s, part. id: '%s', part. sch.: '%s')!"),
INVALID_SMD_XML (400,"SMP:143",ErrorBusinessCode.XML_INVALID,"Invalid service metada. Error: %s"),
// SML integration
SML_INTEGRATION_EXCEPTION ("SMP:150",ErrorBusinessCode.TECHNICAL,"Could not create new DNS entry through SML! Error: %s "),
SML_INTEGRATION_EXCEPTION (500,"SMP:150",ErrorBusinessCode.TECHNICAL,"Could not create new DNS entry through SML! Error: %s "),
//
XML_SIGNING_EXCEPTION ("SMP:500",ErrorBusinessCode.TECHNICAL,"Error occured while signing response!"),
XML_SIGNING_EXCEPTION (500,"SMP:500",ErrorBusinessCode.TECHNICAL,"Error occured while signing response!"),
JAXB_INITIALIZATION ("SMP:511",ErrorBusinessCode.TECHNICAL, "Could not create Unmarshaller for class %s!"),
XML_PARSE_EXCEPTION ("SMP:512",ErrorBusinessCode.TECHNICAL, "Error occured while parsing input stream for %s. Error: %s!"),
JAXB_INITIALIZATION (500,"SMP:511",ErrorBusinessCode.TECHNICAL, "Could not create Unmarshaller for class %s!"),
XML_PARSE_EXCEPTION (500,"SMP:512",ErrorBusinessCode.TECHNICAL, "Error occured while parsing input stream for %s. Error: %s!"),
//
;
int httpCode;
String messageTemplate;
String errorCode;
ErrorBusinessCode errorBusinessCode;
ErrorCode(String errorCode, ErrorBusinessCode ebc, String tmplMsg) {
public int getHttpCode() {
return httpCode;
}
ErrorCode(int httpCode, String errorCode, ErrorBusinessCode ebc, String tmplMsg) {
this.httpCode = httpCode;
this.messageTemplate = tmplMsg;
this.errorCode = errorCode;
this.errorBusinessCode = ebc;
......
......@@ -24,7 +24,7 @@ import static eu.europa.ec.edelivery.smp.exceptions.ErrorCode.MISSING_DOMAIN;
*/
@Service
public class ServiceDomain {
public class DomainService {
public static final Pattern DOMAIN_ID_PATTERN = Pattern.compile("[a-zA-Z0-9]{1,50}");
......
......@@ -60,7 +60,7 @@ public class ServiceGroupService {
private UserDao userDao;
@Autowired
private ServiceDomain serviceDomain;
private DomainService domainService;
@Autowired
private SmlConnector smlConnector;
......@@ -110,7 +110,7 @@ public class ServiceGroupService {
throw ex;
}
// get domain
DBDomain dmn = serviceDomain.getDomain(domain);
DBDomain dmn = domainService.getDomain(domain);
// get servicegroup
Optional<DBServiceGroup> dbServiceGroup = serviceGroupDao.findServiceGroup(normalizedParticipantId.getValue(),
normalizedParticipantId.getScheme());
......
......@@ -52,7 +52,7 @@ public class ServiceMetadataService {
private ServiceGroupDao serviceGroupDao;
@Autowired
private ServiceDomain serviceDomain;
private DomainService domainService;
@Autowired
private ServiceMetadataSigner signer;
......@@ -99,7 +99,7 @@ public class ServiceMetadataService {
normalizedServiceGroupId.getScheme());
}
//test and retrieve domain
DBDomain dbDomain = serviceDomain.getDomain(domain);
DBDomain dbDomain = domainService.getDomain(domain);
Optional<DBServiceMetadata> doc = serviceMetadataDao.findServiceMetadata(normalizedServiceGroupId.getValue(),
normalizedServiceGroupId.getScheme(), normalizedDocId.getValue(), normalizedDocId.getScheme());
......
package eu.europa.ec.edelivery.smp.services;
import eu.europa.ec.edelivery.smp.data.dao.ui.UiDaoService;
import eu.europa.ec.edelivery.smp.data.ui.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class ServiceUIData {
@Autowired
private UiDaoService uiDaoService;
/**
*
* @param page
* @param pageSize
* @param sortField
* @param sortOrder
* @return
*/
public ServiceResult<ServiceGroupRO> getServiceGroupList(int page, int pageSize,
String sortField,
String sortOrder) {
ServiceResult<ServiceGroupRO> sg = new ServiceResult<>();
sg.setPage(page);
sg.setPageSize(pageSize);
long iCnt = uiDaoService.getDataListCount(ServiceGroupRO.class, null);
sg.setCount(iCnt);
if (iCnt > 0) {
List<ServiceGroupRO> lst = uiDaoService.getDataList(ServiceGroupRO.class, page * pageSize, pageSize, sortField, sortOrder, null);
sg.getServiceEntities().addAll(lst);
}
return sg;
}
public void persistServiceGroup(ServiceGroupRO sg) {
uiDaoService.persist(sg);
}
public void persistUser(UserRO ent) {
uiDaoService.persist(ent);
}
public void persistDomain(DomainRO ent) {
uiDaoService.persist(ent);
}
public void persistMetaData(ServiceMetadataRO ent) {
uiDaoService.persist(ent);
}
/**
*
* @param page
* @param pageSize
* @param sortField
* @param sortOrder
* @return
*/
public ServiceResult<UserRO> getUserList(int page, int pageSize,
String sortField,
String sortOrder) {
ServiceResult<UserRO> sg = new ServiceResult<>();
sg.setPage(page);
sg.setPageSize(pageSize);
long iCnt = uiDaoService.getDataListCount(UserRO.class, null);
sg.setCount(iCnt);
if (iCnt > 0) {
List<UserRO> lst = uiDaoService.getDataList(UserRO.class, page * pageSize, pageSize, sortField, sortOrder, null);
sg.getServiceEntities().addAll(lst);
}
return sg;
}
/**
*
* @param page
* @param pageSize
* @param sortField
* @param sortOrder
* @return
*/
public ServiceResult<DomainRO> getDomainList(int page, int pageSize,
String sortField,
String sortOrder) {
ServiceResult<DomainRO> sg = new ServiceResult<>();
sg.setPage(page);
sg.setPageSize(pageSize);
long iCnt = uiDaoService.getDataListCount(DomainRO.class, null);
sg.setCount(iCnt);
if (iCnt > 0) {
List<DomainRO> lst = uiDaoService.getDataList(DomainRO.class, page * pageSize, pageSize, sortField, sortOrder, null);
sg.getServiceEntities().addAll(lst);
}
return sg;
}
public ServiceResult<ServiceMetadataRO> getServiceMetadataList(int page, int pageSize,
String sortField,
String sortOrder) {
ServiceResult<ServiceMetadataRO> sg = new ServiceResult<>();
sg.setPage(page);
sg.setPageSize(pageSize);
long iCnt = uiDaoService.getDataListCount(ServiceMetadataRO.class, null);
sg.setCount(iCnt);
if (iCnt > 0) {
List<ServiceMetadataRO> lst = uiDaoService.getDataList(ServiceMetadataRO.class, page * pageSize, pageSize, sortField, sortOrder, null);
sg.getServiceEntities().addAll(lst);
}
return sg;
}
}
package eu.europa.ec.edelivery.smp.services.ui;
import eu.europa.ec.edelivery.smp.data.dao.BaseDao;
import eu.europa.ec.edelivery.smp.data.dao.DomainDao;
import eu.europa.ec.edelivery.smp.data.model.DBDomain;
import eu.europa.ec.edelivery.smp.data.ui.DomainRO;
import eu.europa.ec.edelivery.smp.data.ui.ServiceResult;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@Service
public class UIDomainService extends UIServiceBase<DBDomain, DomainRO> {
@Autowired
DomainDao domainDao;
@Override
protected BaseDao<DBDomain> getDatabaseDao() {
return domainDao;
}
/**
* Method returns Domain resource object list for page.
*
* @param page
* @param pageSize
* @param sortField
* @param sortOrder
* @return
*/
@Transactional
public ServiceResult<DomainRO> getTableList(int page, int pageSize,
String sortField,
String sortOrder) {
return super.getTableList(page, pageSize, sortField, sortOrder);
}
}
package eu.europa.ec.edelivery.smp.services.ui;
import eu.europa.ec.edelivery.smp.data.dao.BaseDao;
import eu.europa.ec.edelivery.smp.data.model.BaseEntity;
import eu.europa.ec.edelivery.smp.data.model.DBDomain;
import eu.europa.ec.edelivery.smp.data.ui.DomainRO;
import eu.europa.ec.edelivery.smp.data.ui.ServiceResult;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.core.GenericTypeResolver;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
abstract class UIServiceBase<E extends BaseEntity, R> {
private final Class<R> roClass;
private final Class<E> dbClass;
public UIServiceBase() {
Class[] clsArg = GenericTypeResolver.resolveTypeArguments(getClass(), UIServiceBase.class);
dbClass =(Class<E>)clsArg[0];
roClass =(Class<R>)clsArg[1];
}
/**
* Method returns Domain resource object list for page.
*
* @param page
* @param pageSize
* @param sortField
* @param sortOrder
* @return
*/
@Transactional
public ServiceResult<R> getTableList(int page, int pageSize,
String sortField,
String sortOrder) {
ServiceResult<R> sg = new ServiceResult<>();
sg.setPage(page<0?0:page);
sg.setPageSize(pageSize);
long iCnt = getDatabaseDao().getDataListCount(null);
sg.setCount(iCnt);
if (iCnt > 0) {
int iStartIndex = pageSize<0?-1:page * pageSize;
List<E> lst = getDatabaseDao().getDataList(iStartIndex, pageSize, sortField, sortOrder, null);
List<R> lstRo = new ArrayList<>();
for (E d : lst) {
try {
R dro = roClass.newInstance();
BeanUtils.copyProperties(dro,d);
lstRo.add(dro);
} catch (InstantiationException | InvocationTargetException | IllegalAccessException e) {
e.printStackTrace();
}
}
sg.getServiceEntities().addAll(lstRo);
}
return sg;
}
protected abstract BaseDao<E> getDatabaseDao();
}
package eu.europa.ec.edelivery.smp.services.ui;
import eu.europa.ec.edelivery.smp.data.dao.BaseDao;
import eu.europa.ec.edelivery.smp.data.dao.DomainDao;
import eu.europa.ec.edelivery.smp.data.dao.ServiceGroupDao;
import eu.europa.ec.edelivery.smp.data.model.DBDomain;
import eu.europa.ec.edelivery.smp.data.model.DBServiceGroup;
import eu.europa.ec.edelivery.smp.data.ui.DomainRO;
import eu.europa.ec.edelivery.smp.data.ui.ServiceGroupRO;
import eu.europa.ec.edelivery.smp.data.ui.ServiceResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class UIServiceGroupService extends UIServiceBase<DBServiceGroup, ServiceGroupRO> {
@Autowired
ServiceGroupDao serviceGroupDao;
@Override
protected BaseDao<DBServiceGroup> getDatabaseDao() {
return serviceGroupDao;
}
/**
* Method returns Domain resource object list for page.
*
* @param page
* @param pageSize
* @param sortField
* @param sortOrder
* @return
*/
@Transactional
public ServiceResult<ServiceGroupRO> getTableList(int page, int pageSize,
String sortField,
String sortOrder) {
return super.getTableList(page, pageSize, sortField, sortOrder);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment