diff --git a/docs/about/naming_rest_api_brief_introduction.odt b/docs/about/naming_rest_api_brief_introduction.odt index db978abbf8b8ee8b7255e91744f87661348d86e0..1f3b17c0d86949c5536601e31a384f27aa075085 100644 Binary files a/docs/about/naming_rest_api_brief_introduction.odt and b/docs/about/naming_rest_api_brief_introduction.odt differ diff --git a/docs/about/naming_rest_api_brief_introduction.pdf b/docs/about/naming_rest_api_brief_introduction.pdf index a57e2cddc350ad52c2edff95c7e9fca4b8b6d80a..b5fc2de398e6d075a66c72c896e98020a1a43937 100644 Binary files a/docs/about/naming_rest_api_brief_introduction.pdf and b/docs/about/naming_rest_api_brief_introduction.pdf differ diff --git a/docs/about/naming_rest_api_migration.odt b/docs/about/naming_rest_api_migration.odt index c2c8156a26bfe75823d2e73d91a71db0e1284aba..c00b46d02024eb7c2896db69b396c8fec9b726dd 100644 Binary files a/docs/about/naming_rest_api_migration.odt and b/docs/about/naming_rest_api_migration.odt differ diff --git a/docs/about/naming_rest_api_migration.pdf b/docs/about/naming_rest_api_migration.pdf index a03af63e32af5099877147527b8461d414db1b1a..473394585bbff15399d464bcfe64ffc96ed2e402 100644 Binary files a/docs/about/naming_rest_api_migration.pdf and b/docs/about/naming_rest_api_migration.pdf differ diff --git a/src/main/java/org/openepics/names/repository/DeviceGroupRepository.java b/src/main/java/org/openepics/names/repository/DeviceGroupRepository.java index 3e5e8b3f455b9a2fe2ac46c6b4f81c8a5a23bd3a..9aa6d6105d64920ca8d7036bddc4205ab03f4eac 100644 --- a/src/main/java/org/openepics/names/repository/DeviceGroupRepository.java +++ b/src/main/java/org/openepics/names/repository/DeviceGroupRepository.java @@ -65,12 +65,13 @@ public class DeviceGroupRepository { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @return count of device groups */ public Long countDeviceGroups(Status[] statuses, Boolean deleted, - String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description) { + String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who) { return countDeviceGroups(statuses, deleted, - uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, + uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, Boolean.FALSE); } @@ -86,11 +87,12 @@ public class DeviceGroupRepository { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @param includeHistory include history * @return count of device groups */ public Long countDeviceGroups(Status[] statuses, Boolean deleted, - String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, + String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, Boolean includeHistory) { // note @@ -105,7 +107,7 @@ public class DeviceGroupRepository { Root<DeviceGroup> from = cq.from(DeviceGroup.class); cq.where(cb.and(preparePredicatesDeviceGroups(cb, from, cq.subquery(Long.class), statuses, deleted, - uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, + uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, includeHistory).toArray(new Predicate[0]))); cq.select(cb.count(from)); @@ -124,13 +126,14 @@ public class DeviceGroupRepository { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @return list of device groups */ public List<DeviceGroup> readDeviceGroups(Status status, Boolean deleted, - String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description) { + String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who) { return readDeviceGroups(status != null ? new Status[] {status} : null, deleted, - uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, + uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, Boolean.FALSE, null, null, null, null); } @@ -146,6 +149,7 @@ public class DeviceGroupRepository { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @param orderBy order by * @param isAsc is ascending * @param offset offset @@ -153,10 +157,10 @@ public class DeviceGroupRepository { * @return list of device groups */ public List<DeviceGroup> readDeviceGroups(Status[] statuses, Boolean deleted, - String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, + String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, FieldStructure orderBy, Boolean isAsc, Integer offset, Integer limit) { return readDeviceGroups(statuses, deleted, - uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, + uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, Boolean.FALSE, orderBy, isAsc, offset, limit); } @@ -172,6 +176,7 @@ public class DeviceGroupRepository { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @param includeHistory include history * @param orderBy order by * @param isAsc is ascending @@ -180,7 +185,7 @@ public class DeviceGroupRepository { * @return list of device groups */ public List<DeviceGroup> readDeviceGroups(Status[] statuses, Boolean deleted, - String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, + String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, Boolean includeHistory, FieldStructure orderBy, Boolean isAsc, Integer offset, Integer limit) { // note @@ -199,7 +204,7 @@ public class DeviceGroupRepository { Root<DeviceGroup> from = cq.from(DeviceGroup.class); cq.where(cb.and(preparePredicatesDeviceGroups(cb, from, cq.subquery(Long.class), statuses, deleted, - uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, + uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, includeHistory).toArray(new Predicate[0]))); cq.select(from); @@ -263,11 +268,12 @@ public class DeviceGroupRepository { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @param includeHistory include history * @return list of predicates */ private List<Predicate> preparePredicatesDeviceGroups(CriteriaBuilder cb, Root<DeviceGroup> from, Subquery<Long> sub, Status[] statuses, Boolean deleted, - String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, + String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, Boolean includeHistory) { List<Predicate> predicates = new ArrayList<>(); @@ -329,7 +335,7 @@ public class DeviceGroupRepository { predicates.add(cb.and(cb.equal(from.get(NameStructure.FIELD_UUID), RepositoryUtil.preparePattern(uuid)))); } if (!StringUtils.isEmpty(parentUuid)) { - predicates.add(cb.and(cb.equal(from.get(System.FIELD_PARENT_UUID), RepositoryUtil.preparePattern(parentUuid)))); + predicates.add(cb.and(cb.equal(from.get(DeviceGroup.FIELD_PARENT_UUID), RepositoryUtil.preparePattern(parentUuid)))); } if (!StringUtils.isEmpty(name)) { predicates.add(cb.and(cb.like(from.get(Structure.FIELD_NAME), RepositoryUtil.preparePattern(name)))); @@ -346,10 +352,144 @@ public class DeviceGroupRepository { if (!StringUtils.isEmpty(description)) { predicates.add(cb.and(cb.like(from.get(NameStructure.FIELD_DESCRIPTION), RepositoryUtil.preparePattern(description)))); } + if (!StringUtils.isEmpty(who)) { + predicates.add(cb.and(cb.like(from.get(NameStructure.FIELD_REQUESTED_BY), RepositoryUtil.preparePattern(who)))); + } return predicates; } + /** + * Count device groups history. + * + * @param uuid uuid + * @param parentUuid parent uuid + * @param name name + * @param mnemonic mnemonic + * @param mnemonicEquivalence mnemonic equivalence + * @param mnemonicPath mnemonic path + * @param description description + * @param who who + * @return count of device groups + */ + public Long countDeviceGroupsHistory( + String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who) { + + // note + // use of function for mnemonic path + // deleted - null + // includeHistory - true + // where + // queryFields, queryValues + + CriteriaBuilder cb = em.getCriteriaBuilder(); + CriteriaQuery<Long> cq = cb.createQuery(Long.class); + Root<DeviceGroup> from = cq.from(DeviceGroup.class); + + Subquery<String> sub = cq.subquery(String.class); + Root<DeviceGroup> fromSub = sub.from(DeviceGroup.class); + sub.where(cb.and(preparePredicatesDeviceGroups(cb, fromSub, null, null, null, + uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, + Boolean.TRUE).toArray(new Predicate[0]))); + sub.select(fromSub.get(NameStructure.FIELD_UUID)); + + cq.where(cb.and(cb.in(from.get(NameStructure.FIELD_UUID)).value(sub))); + cq.select(cb.count(from)); + + return em.createQuery(cq).getSingleResult(); + } + + /** + * Find device groups history. + * + * @param uuid uuid + * @param parentUuid parent uuid + * @param name name + * @param mnemonic mnemonic + * @param mnemonicEquivalence mnemonic equivalence + * @param mnemonicPath mnemonic path + * @param description description + * @param who who + * @param orderBy order by + * @param isAsc is ascending + * @param offset offset + * @param limit limit + * @return list of device groups + */ + public List<DeviceGroup> readDeviceGroupsHistory( + String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, + FieldStructure orderBy, Boolean isAsc, Integer offset, Integer limit) { + + // note + // use of function for mnemonic path + // deleted - null + // includeHistory - true + // where + // queryFields, queryValues + // order + // orderBy, isAsc + // paging + // offset, limit + + CriteriaBuilder cb = em.getCriteriaBuilder(); + CriteriaQuery<DeviceGroup> cq = cb.createQuery(DeviceGroup.class); + Root<DeviceGroup> from = cq.from(DeviceGroup.class); + + Subquery<String> sub = cq.subquery(String.class); + Root<DeviceGroup> fromSub = sub.from(DeviceGroup.class); + sub.where(cb.and(preparePredicatesDeviceGroups(cb, fromSub, null, null, null, + uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, + Boolean.TRUE).toArray(new Predicate[0]))); + sub.select(fromSub.get(NameStructure.FIELD_UUID)); + + cq.where(cb.and(cb.in(from.get(NameStructure.FIELD_UUID)).value(sub))); + cq.select(from); + + if (orderBy != null) { + if (BooleanUtils.toBoolean(isAsc)) { + if (FieldStructure.NAME.equals(orderBy)) { + cq.orderBy(cb.asc(from.get(Structure.FIELD_NAME))); + } else if (FieldStructure.MNEMONIC.equals(orderBy)) { + cq.orderBy(cb.asc(from.get(Structure.FIELD_MNEMONIC))); + } else if (FieldStructure.MNEMONICEQUIVALENCE.equals(orderBy)) { + cq.orderBy(cb.asc(from.get(Structure.FIELD_MNEMONIC_EQUIVALENCE))); + } else if (FieldStructure.MNEMONICPATH.equals(orderBy)) { + cq.orderBy(cb.asc(cb.function(DeviceGroup.FUNCTION_GET_MNEMONIC_PATH_DEVICEGROUP, String.class, from.get(NameStructure.FIELD_UUID)))); + } else if (FieldStructure.DESCRIPTION.equals(orderBy)) { + cq.orderBy(cb.asc(from.get(NameStructure.FIELD_DESCRIPTION))); + } else if (FieldStructure.WHEN.equals(orderBy)) { + cq.orderBy(cb.asc(from.get(NameStructure.FIELD_REQUESTED))); + } else { + cq.orderBy(cb.asc(from.get(NameStructure.FIELD_UUID)), cb.asc(from.get(Persistable.FIELD_ID))); + } + } else { + if (FieldStructure.NAME.equals(orderBy)) { + cq.orderBy(cb.desc(from.get(Structure.FIELD_NAME))); + } else if (FieldStructure.MNEMONIC.equals(orderBy)) { + cq.orderBy(cb.desc(from.get(Structure.FIELD_MNEMONIC))); + } else if (FieldStructure.MNEMONICEQUIVALENCE.equals(orderBy)) { + cq.orderBy(cb.desc(from.get(Structure.FIELD_MNEMONIC_EQUIVALENCE))); + } else if (FieldStructure.MNEMONICPATH.equals(orderBy)) { + cq.orderBy(cb.desc(cb.function(DeviceGroup.FUNCTION_GET_MNEMONIC_PATH_DEVICEGROUP, String.class, from.get(NameStructure.FIELD_UUID)))); + } else if (FieldStructure.DESCRIPTION.equals(orderBy)) { + cq.orderBy(cb.desc(from.get(NameStructure.FIELD_DESCRIPTION))); + } else if (FieldStructure.WHEN.equals(orderBy)) { + cq.orderBy(cb.desc(from.get(NameStructure.FIELD_REQUESTED))); + } else { + cq.orderBy(cb.desc(from.get(NameStructure.FIELD_UUID)), cb.desc(from.get(Persistable.FIELD_ID))); + } + } + } + + TypedQuery<DeviceGroup> query = em.createQuery(cq); + if (offset != null && limit != null) { + query.setFirstResult(offset * limit); + query.setMaxResults(limit); + } + + return query.getResultList(); + } + /** * Persist device group into persistence context. * diff --git a/src/main/java/org/openepics/names/repository/DeviceTypeRepository.java b/src/main/java/org/openepics/names/repository/DeviceTypeRepository.java index 8327d67ae47800c1eb3f21a831467ce1b2893795..c7c66ab40cf1e50591779668b6ba6ad023a00323 100644 --- a/src/main/java/org/openepics/names/repository/DeviceTypeRepository.java +++ b/src/main/java/org/openepics/names/repository/DeviceTypeRepository.java @@ -65,12 +65,13 @@ public class DeviceTypeRepository { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @return count of device types */ public Long countDeviceTypes(Status[] statuses, Boolean deleted, - String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description) { + String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who) { return countDeviceTypes(statuses, deleted, - uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, + uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, Boolean.FALSE); } @@ -86,11 +87,12 @@ public class DeviceTypeRepository { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @param includeHistory include history * @return count of device types */ public Long countDeviceTypes(Status[] statuses, Boolean deleted, - String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, + String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, Boolean includeHistory) { // note @@ -105,7 +107,7 @@ public class DeviceTypeRepository { Root<DeviceType> from = cq.from(DeviceType.class); cq.where(cb.and(preparePredicatesDeviceTypes(cb, from, cq.subquery(Long.class), statuses, deleted, - uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, + uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, includeHistory).toArray(new Predicate[0]))); cq.select(cb.count(from)); @@ -124,13 +126,14 @@ public class DeviceTypeRepository { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @return list of device types */ public List<DeviceType> readDeviceTypes(Status status, Boolean deleted, - String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description) { + String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who) { return readDeviceTypes(status != null ? new Status[] {status} : null, deleted, - uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, + uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, Boolean.FALSE, null, null, null, null); } @@ -146,6 +149,7 @@ public class DeviceTypeRepository { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @param orderBy order by * @param isAsc is ascending * @param offset offset @@ -153,10 +157,10 @@ public class DeviceTypeRepository { * @return list of device types */ public List<DeviceType> readDeviceTypes(Status[] statuses, Boolean deleted, - String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, + String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, FieldStructure orderBy, Boolean isAsc, Integer offset, Integer limit) { return readDeviceTypes(statuses, deleted, - uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, + uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, Boolean.FALSE, orderBy, isAsc, offset, limit); } @@ -172,6 +176,7 @@ public class DeviceTypeRepository { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @param includeHistory include history * @param orderBy order by * @param isAsc is ascending @@ -180,7 +185,7 @@ public class DeviceTypeRepository { * @return list of device types */ public List<DeviceType> readDeviceTypes(Status[] statuses, Boolean deleted, - String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, + String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, Boolean includeHistory, FieldStructure orderBy, Boolean isAsc, Integer offset, Integer limit) { // note @@ -199,7 +204,7 @@ public class DeviceTypeRepository { Root<DeviceType> from = cq.from(DeviceType.class); cq.where(cb.and(preparePredicatesDeviceTypes(cb, from, cq.subquery(Long.class), statuses, deleted, - uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, + uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, includeHistory).toArray(new Predicate[0]))); cq.select(from); @@ -263,11 +268,12 @@ public class DeviceTypeRepository { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @param includeHistory include history * @return list of predicates */ private List<Predicate> preparePredicatesDeviceTypes(CriteriaBuilder cb, Root<DeviceType> from, Subquery<Long> sub, Status[] statuses, Boolean deleted, - String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, + String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, Boolean includeHistory) { List<Predicate> predicates = new ArrayList<>(); @@ -329,7 +335,7 @@ public class DeviceTypeRepository { predicates.add(cb.and(cb.equal(from.get(NameStructure.FIELD_UUID), RepositoryUtil.preparePattern(uuid)))); } if (!StringUtils.isEmpty(parentUuid)) { - predicates.add(cb.and(cb.equal(from.get(System.FIELD_PARENT_UUID), RepositoryUtil.preparePattern(parentUuid)))); + predicates.add(cb.and(cb.equal(from.get(DeviceType.FIELD_PARENT_UUID), RepositoryUtil.preparePattern(parentUuid)))); } if (!StringUtils.isEmpty(name)) { predicates.add(cb.and(cb.like(from.get(Structure.FIELD_NAME), RepositoryUtil.preparePattern(name)))); @@ -346,10 +352,144 @@ public class DeviceTypeRepository { if (!StringUtils.isEmpty(description)) { predicates.add(cb.and(cb.like(from.get(NameStructure.FIELD_DESCRIPTION), RepositoryUtil.preparePattern(description)))); } + if (!StringUtils.isEmpty(who)) { + predicates.add(cb.and(cb.like(from.get(NameStructure.FIELD_REQUESTED_BY), RepositoryUtil.preparePattern(who)))); + } return predicates; } + /** + * Count device types history. + * + * @param uuid uuid + * @param parentUuid parent uuid + * @param name name + * @param mnemonic mnemonic + * @param mnemonicEquivalence mnemonic equivalence + * @param mnemonicPath mnemonic path + * @param description description + * @param who who + * @return count of device types + */ + public Long countDeviceTypesHistory( + String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who) { + + // note + // use of function for mnemonic path + // deleted - null + // includeHistory - true + // where + // queryFields, queryValues + + CriteriaBuilder cb = em.getCriteriaBuilder(); + CriteriaQuery<Long> cq = cb.createQuery(Long.class); + Root<DeviceType> from = cq.from(DeviceType.class); + + Subquery<String> sub = cq.subquery(String.class); + Root<DeviceType> fromSub = sub.from(DeviceType.class); + sub.where(cb.and(preparePredicatesDeviceTypes(cb, fromSub, null, null, null, + uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, + Boolean.TRUE).toArray(new Predicate[0]))); + sub.select(fromSub.get(NameStructure.FIELD_UUID)); + + cq.where(cb.and(cb.in(from.get(NameStructure.FIELD_UUID)).value(sub))); + cq.select(cb.count(from)); + + return em.createQuery(cq).getSingleResult(); + } + + /** + * Find device types history. + * + * @param uuid uuid + * @param parentUuid parent uuid + * @param name name + * @param mnemonic mnemonic + * @param mnemonicEquivalence mnemonic equivalence + * @param mnemonicPath mnemonic path + * @param description description + * @param who who + * @param orderBy order by + * @param isAsc is ascending + * @param offset offset + * @param limit limit + * @return list of device types + */ + public List<DeviceType> readDeviceTypesHistory( + String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, + FieldStructure orderBy, Boolean isAsc, Integer offset, Integer limit) { + + // note + // use of function for mnemonic path + // deleted - null + // includeHistory - true + // where + // queryFields, queryValues + // order + // orderBy, isAsc + // paging + // offset, limit + + CriteriaBuilder cb = em.getCriteriaBuilder(); + CriteriaQuery<DeviceType> cq = cb.createQuery(DeviceType.class); + Root<DeviceType> from = cq.from(DeviceType.class); + + Subquery<String> sub = cq.subquery(String.class); + Root<DeviceType> fromSub = sub.from(DeviceType.class); + sub.where(cb.and(preparePredicatesDeviceTypes(cb, fromSub, null, null, null, + uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, + Boolean.TRUE).toArray(new Predicate[0]))); + sub.select(fromSub.get(NameStructure.FIELD_UUID)); + + cq.where(cb.and(cb.in(from.get(NameStructure.FIELD_UUID)).value(sub))); + cq.select(from); + + if (orderBy != null) { + if (BooleanUtils.toBoolean(isAsc)) { + if (FieldStructure.NAME.equals(orderBy)) { + cq.orderBy(cb.asc(from.get(Structure.FIELD_NAME))); + } else if (FieldStructure.MNEMONIC.equals(orderBy)) { + cq.orderBy(cb.asc(from.get(Structure.FIELD_MNEMONIC))); + } else if (FieldStructure.MNEMONICEQUIVALENCE.equals(orderBy)) { + cq.orderBy(cb.asc(from.get(Structure.FIELD_MNEMONIC_EQUIVALENCE))); + } else if (FieldStructure.MNEMONICPATH.equals(orderBy)) { + cq.orderBy(cb.asc(cb.function(DeviceType.FUNCTION_GET_MNEMONIC_PATH_DEVICETYPE, String.class, from.get(NameStructure.FIELD_UUID)))); + } else if (FieldStructure.DESCRIPTION.equals(orderBy)) { + cq.orderBy(cb.asc(from.get(NameStructure.FIELD_DESCRIPTION))); + } else if (FieldStructure.WHEN.equals(orderBy)) { + cq.orderBy(cb.asc(from.get(NameStructure.FIELD_REQUESTED))); + } else { + cq.orderBy(cb.asc(from.get(NameStructure.FIELD_UUID)), cb.asc(from.get(Persistable.FIELD_ID))); + } + } else { + if (FieldStructure.NAME.equals(orderBy)) { + cq.orderBy(cb.desc(from.get(Structure.FIELD_NAME))); + } else if (FieldStructure.MNEMONIC.equals(orderBy)) { + cq.orderBy(cb.desc(from.get(Structure.FIELD_MNEMONIC))); + } else if (FieldStructure.MNEMONICEQUIVALENCE.equals(orderBy)) { + cq.orderBy(cb.desc(from.get(Structure.FIELD_MNEMONIC_EQUIVALENCE))); + } else if (FieldStructure.MNEMONICPATH.equals(orderBy)) { + cq.orderBy(cb.desc(cb.function(DeviceType.FUNCTION_GET_MNEMONIC_PATH_DEVICETYPE, String.class, from.get(NameStructure.FIELD_UUID)))); + } else if (FieldStructure.DESCRIPTION.equals(orderBy)) { + cq.orderBy(cb.desc(from.get(NameStructure.FIELD_DESCRIPTION))); + } else if (FieldStructure.WHEN.equals(orderBy)) { + cq.orderBy(cb.desc(from.get(NameStructure.FIELD_REQUESTED))); + } else { + cq.orderBy(cb.desc(from.get(NameStructure.FIELD_UUID)), cb.desc(from.get(Persistable.FIELD_ID))); + } + } + } + + TypedQuery<DeviceType> query = em.createQuery(cq); + if (offset != null && limit != null) { + query.setFirstResult(offset * limit); + query.setMaxResults(limit); + } + + return query.getResultList(); + } + /** * Persist device type into persistence context. * diff --git a/src/main/java/org/openepics/names/repository/DisciplineRepository.java b/src/main/java/org/openepics/names/repository/DisciplineRepository.java index 7754006dc8efee1a891e32b12216ce4e74b5f0f3..cd35c2f26128019c7bd9ce1f604d870839a5ff0a 100644 --- a/src/main/java/org/openepics/names/repository/DisciplineRepository.java +++ b/src/main/java/org/openepics/names/repository/DisciplineRepository.java @@ -63,12 +63,13 @@ public class DisciplineRepository { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @return count of disciplines */ public Long countDisciplines(Status[] statuses, Boolean deleted, - String uuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description) { + String uuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who) { return countDisciplines(statuses, deleted, - uuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, + uuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, Boolean.FALSE); } @@ -83,11 +84,12 @@ public class DisciplineRepository { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @param includeHistory include history * @return count of disciplines */ public Long countDisciplines(Status[] statuses, Boolean deleted, - String uuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, + String uuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, Boolean includeHistory) { // note @@ -102,7 +104,7 @@ public class DisciplineRepository { Root<Discipline> from = cq.from(Discipline.class); cq.where(cb.and(preparePredicatesDisciplines(cb, from, cq.subquery(Long.class), statuses, deleted, - uuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, + uuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, includeHistory).toArray(new Predicate[0]))); cq.select(cb.count(from)); @@ -120,13 +122,14 @@ public class DisciplineRepository { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @return list of disciplines */ public List<Discipline> readDisciplines(Status status, Boolean deleted, - String uuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description) { + String uuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who) { return readDisciplines(status != null ? new Status[] {status} : null, deleted, - uuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, + uuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, Boolean.FALSE, null, null, null, null); } @@ -148,10 +151,10 @@ public class DisciplineRepository { * @return list of disciplines */ public List<Discipline> readDisciplines(Status[] statuses, Boolean deleted, - String uuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, + String uuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, FieldStructure orderBy, Boolean isAsc, Integer offset, Integer limit) { return readDisciplines(statuses, deleted, - uuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, + uuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, Boolean.FALSE, orderBy, isAsc, offset, limit); } @@ -166,6 +169,7 @@ public class DisciplineRepository { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @param includeHistory include history * @param orderBy order by * @param isAsc is ascending @@ -174,7 +178,7 @@ public class DisciplineRepository { * @return list of disciplines */ public List<Discipline> readDisciplines(Status[] statuses, Boolean deleted, - String uuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, + String uuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, Boolean includeHistory, FieldStructure orderBy, Boolean isAsc, Integer offset, Integer limit) { // note @@ -193,7 +197,7 @@ public class DisciplineRepository { Root<Discipline> from = cq.from(Discipline.class); cq.where(cb.and(preparePredicatesDisciplines(cb, from, cq.subquery(Long.class), statuses, deleted, - uuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, + uuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, includeHistory).toArray(new Predicate[0]))); cq.select(from); @@ -256,11 +260,12 @@ public class DisciplineRepository { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @param includeHistory include history * @return list of predicates */ private List<Predicate> preparePredicatesDisciplines(CriteriaBuilder cb, Root<Discipline> from, Subquery<Long> sub, Status[] statuses, Boolean deleted, - String uuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, + String uuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, Boolean includeHistory) { List<Predicate> predicates = new ArrayList<>(); @@ -336,10 +341,140 @@ public class DisciplineRepository { if (!StringUtils.isEmpty(description)) { predicates.add(cb.and(cb.like(from.get(NameStructure.FIELD_DESCRIPTION), RepositoryUtil.preparePattern(description)))); } + if (!StringUtils.isEmpty(who)) { + predicates.add(cb.and(cb.like(from.get(NameStructure.FIELD_REQUESTED_BY), RepositoryUtil.preparePattern(who)))); + } return predicates; } + /** + * Count disciplines history. + * + * @param uuid uuid + * @param name name + * @param mnemonic mnemonic + * @param mnemonicEquivalence mnemonic equivalence + * @param mnemonicPath mnemonic path + * @param description description + * @param who who + * @return count of disciplines + */ + public Long countDisciplinesHistory( + String uuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who) { + + // note + // deleted - null + // includeHistory - true + // where + // queryFields, queryValues + + CriteriaBuilder cb = em.getCriteriaBuilder(); + CriteriaQuery<Long> cq = cb.createQuery(Long.class); + Root<Discipline> from = cq.from(Discipline.class); + + Subquery<String> sub = cq.subquery(String.class); + Root<Discipline> fromSub = sub.from(Discipline.class); + sub.where(cb.and(preparePredicatesDisciplines(cb, fromSub, null, null, null, + uuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, + Boolean.TRUE).toArray(new Predicate[0]))); + sub.select(fromSub.get(NameStructure.FIELD_UUID)); + + cq.where(cb.and(cb.in(from.get(NameStructure.FIELD_UUID)).value(sub))); + cq.select(cb.count(from)); + + return em.createQuery(cq).getSingleResult(); + } + + /** + * Find disciplines history. + * + * @param uuid uuid + * @param name name + * @param mnemonic mnemonic + * @param mnemonicEquivalence mnemonic equivalence + * @param mnemonicPath mnemonic path + * @param description description + * @param who who + * @param orderBy order by + * @param isAsc is ascending + * @param offset offset + * @param limit limit + * @return list of disciplines + */ + public List<Discipline> readDisciplinesHistory( + String uuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, + FieldStructure orderBy, Boolean isAsc, Integer offset, Integer limit) { + + // note + // deleted - null + // includeHistory - true + // where + // queryFields, queryValues + // order + // orderBy, isAsc + // paging + // offset, limit + + CriteriaBuilder cb = em.getCriteriaBuilder(); + CriteriaQuery<Discipline> cq = cb.createQuery(Discipline.class); + Root<Discipline> from = cq.from(Discipline.class); + + Subquery<String> sub = cq.subquery(String.class); + Root<Discipline> fromSub = sub.from(Discipline.class); + sub.where(cb.and(preparePredicatesDisciplines(cb, fromSub, null, null, null, + uuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, + Boolean.TRUE).toArray(new Predicate[0]))); + sub.select(fromSub.get(NameStructure.FIELD_UUID)); + + cq.where(cb.and(cb.in(from.get(NameStructure.FIELD_UUID)).value(sub))); + cq.select(from); + + if (orderBy != null) { + if (BooleanUtils.toBoolean(isAsc)) { + if (FieldStructure.NAME.equals(orderBy)) { + cq.orderBy(cb.asc(from.get(Structure.FIELD_NAME))); + } else if (FieldStructure.MNEMONIC.equals(orderBy)) { + cq.orderBy(cb.asc(from.get(Structure.FIELD_MNEMONIC))); + } else if (FieldStructure.MNEMONICEQUIVALENCE.equals(orderBy)) { + cq.orderBy(cb.asc(from.get(Structure.FIELD_MNEMONIC_EQUIVALENCE))); + } else if (FieldStructure.MNEMONICPATH.equals(orderBy)) { + cq.orderBy(cb.asc(from.get(Structure.FIELD_MNEMONIC))); + } else if (FieldStructure.DESCRIPTION.equals(orderBy)) { + cq.orderBy(cb.asc(from.get(NameStructure.FIELD_DESCRIPTION))); + } else if (FieldStructure.WHEN.equals(orderBy)) { + cq.orderBy(cb.asc(from.get(NameStructure.FIELD_REQUESTED))); + } else { + cq.orderBy(cb.asc(from.get(NameStructure.FIELD_UUID)), cb.asc(from.get(Persistable.FIELD_ID))); + } + } else { + if (FieldStructure.NAME.equals(orderBy)) { + cq.orderBy(cb.desc(from.get(Structure.FIELD_NAME))); + } else if (FieldStructure.MNEMONIC.equals(orderBy)) { + cq.orderBy(cb.desc(from.get(Structure.FIELD_MNEMONIC))); + } else if (FieldStructure.MNEMONICEQUIVALENCE.equals(orderBy)) { + cq.orderBy(cb.desc(from.get(Structure.FIELD_MNEMONIC_EQUIVALENCE))); + } else if (FieldStructure.MNEMONICPATH.equals(orderBy)) { + cq.orderBy(cb.desc(from.get(Structure.FIELD_MNEMONIC))); + } else if (FieldStructure.DESCRIPTION.equals(orderBy)) { + cq.orderBy(cb.desc(from.get(NameStructure.FIELD_DESCRIPTION))); + } else if (FieldStructure.WHEN.equals(orderBy)) { + cq.orderBy(cb.desc(from.get(NameStructure.FIELD_REQUESTED))); + } else { + cq.orderBy(cb.desc(from.get(NameStructure.FIELD_UUID)), cb.desc(from.get(Persistable.FIELD_ID))); + } + } + } + + TypedQuery<Discipline> query = em.createQuery(cq); + if (offset != null && limit != null) { + query.setFirstResult(offset * limit); + query.setMaxResults(limit); + } + + return query.getResultList(); + } + /** * Persist discipline into persistence context. * diff --git a/src/main/java/org/openepics/names/repository/SubsystemRepository.java b/src/main/java/org/openepics/names/repository/SubsystemRepository.java index c33ef3798d08c5f4a7c1db73117cc20f46a526b7..c5642eb3354f1f5856c7c3c4e2ef06cc15f6583a 100644 --- a/src/main/java/org/openepics/names/repository/SubsystemRepository.java +++ b/src/main/java/org/openepics/names/repository/SubsystemRepository.java @@ -65,12 +65,13 @@ public class SubsystemRepository { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @return count of subsystems */ public Long countSubsystems(Status[] statuses, Boolean deleted, - String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description) { + String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who) { return countSubsystems(statuses, deleted, - uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, + uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, Boolean.FALSE); } @@ -86,11 +87,12 @@ public class SubsystemRepository { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @param includeHistory include history * @return count of subsystems */ public Long countSubsystems(Status[] statuses, Boolean deleted, - String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, + String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, Boolean includeHistory) { // note @@ -105,7 +107,7 @@ public class SubsystemRepository { Root<Subsystem> from = cq.from(Subsystem.class); cq.where(cb.and(preparePredicatesSubsystems(cb, from, cq.subquery(Long.class), statuses, deleted, - uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, + uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, includeHistory).toArray(new Predicate[0]))); cq.select(cb.count(from)); @@ -124,13 +126,14 @@ public class SubsystemRepository { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @return list of subsystems */ public List<Subsystem> readSubsystems(Status status, Boolean deleted, - String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description) { + String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who) { return readSubsystems(status != null ? new Status[] {status} : null, deleted, - uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, + uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, Boolean.FALSE, null, null, null, null); } @@ -146,6 +149,7 @@ public class SubsystemRepository { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @param orderBy order by * @param isAsc is ascending * @param offset offset @@ -153,10 +157,10 @@ public class SubsystemRepository { * @return list of subsystems */ public List<Subsystem> readSubsystems(Status[] statuses, Boolean deleted, - String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, + String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, FieldStructure orderBy, Boolean isAsc, Integer offset, Integer limit) { return readSubsystems(statuses, deleted, - uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, + uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, Boolean.FALSE, orderBy, isAsc, offset, limit); } @@ -172,6 +176,7 @@ public class SubsystemRepository { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @param includeHistory include history * @param orderBy order by * @param isAsc is ascending @@ -180,7 +185,7 @@ public class SubsystemRepository { * @return list of subsystems */ public List<Subsystem> readSubsystems(Status[] statuses, Boolean deleted, - String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, + String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, Boolean includeHistory, FieldStructure orderBy, Boolean isAsc, Integer offset, Integer limit) { // note @@ -199,7 +204,7 @@ public class SubsystemRepository { Root<Subsystem> from = cq.from(Subsystem.class); cq.where(cb.and(preparePredicatesSubsystems(cb, from, cq.subquery(Long.class), statuses, deleted, - uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, + uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, includeHistory).toArray(new Predicate[0]))); cq.select(from); @@ -263,11 +268,12 @@ public class SubsystemRepository { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @param includeHistory include history * @return list of predicates */ private List<Predicate> preparePredicatesSubsystems(CriteriaBuilder cb, Root<Subsystem> from, Subquery<Long> sub, Status[] statuses, Boolean deleted, - String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, + String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, Boolean includeHistory) { List<Predicate> predicates = new ArrayList<>(); @@ -329,7 +335,7 @@ public class SubsystemRepository { predicates.add(cb.and(cb.equal(from.get(NameStructure.FIELD_UUID), RepositoryUtil.preparePattern(uuid)))); } if (!StringUtils.isEmpty(parentUuid)) { - predicates.add(cb.and(cb.equal(from.get(System.FIELD_PARENT_UUID), RepositoryUtil.preparePattern(parentUuid)))); + predicates.add(cb.and(cb.equal(from.get(Subsystem.FIELD_PARENT_UUID), RepositoryUtil.preparePattern(parentUuid)))); } if (!StringUtils.isEmpty(name)) { predicates.add(cb.and(cb.like(from.get(Structure.FIELD_NAME), RepositoryUtil.preparePattern(name)))); @@ -346,10 +352,144 @@ public class SubsystemRepository { if (!StringUtils.isEmpty(description)) { predicates.add(cb.and(cb.like(from.get(NameStructure.FIELD_DESCRIPTION), RepositoryUtil.preparePattern(description)))); } + if (!StringUtils.isEmpty(who)) { + predicates.add(cb.and(cb.like(from.get(NameStructure.FIELD_REQUESTED_BY), RepositoryUtil.preparePattern(who)))); + } return predicates; } + /** + * Count subsystems history. + * + * @param uuid uuid + * @param parentUuid parent uuid + * @param name name + * @param mnemonic mnemonic + * @param mnemonicEquivalence mnemonic equivalence + * @param mnemonicPath mnemonic path + * @param description description + * @param who who + * @return count of subsystems + */ + public Long countSubsystemsHistory( + String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who) { + + // note + // use of function for mnemonic path + // deleted - null + // includeHistory - true + // where + // queryFields, queryValues + + CriteriaBuilder cb = em.getCriteriaBuilder(); + CriteriaQuery<Long> cq = cb.createQuery(Long.class); + Root<Subsystem> from = cq.from(Subsystem.class); + + Subquery<String> sub = cq.subquery(String.class); + Root<Subsystem> fromSub = sub.from(Subsystem.class); + sub.where(cb.and(preparePredicatesSubsystems(cb, fromSub, null, null, null, + uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, + Boolean.TRUE).toArray(new Predicate[0]))); + sub.select(fromSub.get(NameStructure.FIELD_UUID)); + + cq.where(cb.and(cb.in(from.get(NameStructure.FIELD_UUID)).value(sub))); + cq.select(cb.count(from)); + + return em.createQuery(cq).getSingleResult(); + } + + /** + * Find subsystems history. + * + * @param uuid uuid + * @param parentUuid parent uuid + * @param name name + * @param mnemonic mnemonic + * @param mnemonicEquivalence mnemonic equivalence + * @param mnemonicPath mnemonic path + * @param description description + * @param who who + * @param orderBy order by + * @param isAsc is ascending + * @param offset offset + * @param limit limit + * @return list of subsystems + */ + public List<Subsystem> readSubsystemsHistory( + String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, + FieldStructure orderBy, Boolean isAsc, Integer offset, Integer limit) { + + // note + // use of function for mnemonic path + // deleted - null + // includeHistory - true + // where + // queryFields, queryValues + // order + // orderBy, isAsc + // paging + // offset, limit + + CriteriaBuilder cb = em.getCriteriaBuilder(); + CriteriaQuery<Subsystem> cq = cb.createQuery(Subsystem.class); + Root<Subsystem> from = cq.from(Subsystem.class); + + Subquery<String> sub = cq.subquery(String.class); + Root<Subsystem> fromSub = sub.from(Subsystem.class); + sub.where(cb.and(preparePredicatesSubsystems(cb, fromSub, null, null, null, + uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, + Boolean.TRUE).toArray(new Predicate[0]))); + sub.select(fromSub.get(NameStructure.FIELD_UUID)); + + cq.where(cb.and(cb.in(from.get(NameStructure.FIELD_UUID)).value(sub))); + cq.select(from); + + if (orderBy != null) { + if (BooleanUtils.toBoolean(isAsc)) { + if (FieldStructure.NAME.equals(orderBy)) { + cq.orderBy(cb.asc(from.get(Structure.FIELD_NAME))); + } else if (FieldStructure.MNEMONIC.equals(orderBy)) { + cq.orderBy(cb.asc(from.get(Structure.FIELD_MNEMONIC))); + } else if (FieldStructure.MNEMONICEQUIVALENCE.equals(orderBy)) { + cq.orderBy(cb.asc(from.get(Structure.FIELD_MNEMONIC_EQUIVALENCE))); + } else if (FieldStructure.MNEMONICPATH.equals(orderBy)) { + cq.orderBy(cb.asc(cb.function(Subsystem.FUNCTION_GET_MNEMONIC_PATH_SUBSYSTEM, String.class, from.get(NameStructure.FIELD_UUID)))); + } else if (FieldStructure.DESCRIPTION.equals(orderBy)) { + cq.orderBy(cb.asc(from.get(NameStructure.FIELD_DESCRIPTION))); + } else if (FieldStructure.WHEN.equals(orderBy)) { + cq.orderBy(cb.asc(from.get(NameStructure.FIELD_REQUESTED))); + } else { + cq.orderBy(cb.asc(from.get(NameStructure.FIELD_UUID)), cb.asc(from.get(Persistable.FIELD_ID))); + } + } else { + if (FieldStructure.NAME.equals(orderBy)) { + cq.orderBy(cb.desc(from.get(Structure.FIELD_NAME))); + } else if (FieldStructure.MNEMONIC.equals(orderBy)) { + cq.orderBy(cb.desc(from.get(Structure.FIELD_MNEMONIC))); + } else if (FieldStructure.MNEMONICEQUIVALENCE.equals(orderBy)) { + cq.orderBy(cb.desc(from.get(Structure.FIELD_MNEMONIC_EQUIVALENCE))); + } else if (FieldStructure.MNEMONICPATH.equals(orderBy)) { + cq.orderBy(cb.desc(cb.function(Subsystem.FUNCTION_GET_MNEMONIC_PATH_SUBSYSTEM, String.class, from.get(NameStructure.FIELD_UUID)))); + } else if (FieldStructure.DESCRIPTION.equals(orderBy)) { + cq.orderBy(cb.desc(from.get(NameStructure.FIELD_DESCRIPTION))); + } else if (FieldStructure.WHEN.equals(orderBy)) { + cq.orderBy(cb.desc(from.get(NameStructure.FIELD_REQUESTED))); + } else { + cq.orderBy(cb.desc(from.get(NameStructure.FIELD_UUID)), cb.desc(from.get(Persistable.FIELD_ID))); + } + } + } + + TypedQuery<Subsystem> query = em.createQuery(cq); + if (offset != null && limit != null) { + query.setFirstResult(offset * limit); + query.setMaxResults(limit); + } + + return query.getResultList(); + } + /** * Persist subsystem into persistence context. * diff --git a/src/main/java/org/openepics/names/repository/SystemGroupRepository.java b/src/main/java/org/openepics/names/repository/SystemGroupRepository.java index 0a46072e0b54a91f23d7b13800e16e96321615fa..77add4946b76e1f6038b476d3b1d37f6b00d1398 100644 --- a/src/main/java/org/openepics/names/repository/SystemGroupRepository.java +++ b/src/main/java/org/openepics/names/repository/SystemGroupRepository.java @@ -63,12 +63,13 @@ public class SystemGroupRepository { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @return count of system groups */ public Long countSystemGroups(Status[] statuses, Boolean deleted, - String uuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description) { + String uuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who) { return countSystemGroups(statuses, deleted, - uuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, + uuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, Boolean.FALSE); } @@ -83,11 +84,12 @@ public class SystemGroupRepository { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @param includeHistory include history * @return count of system groups */ public Long countSystemGroups(Status[] statuses, Boolean deleted, - String uuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, + String uuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, Boolean includeHistory) { // where @@ -100,7 +102,7 @@ public class SystemGroupRepository { Root<SystemGroup> from = cq.from(SystemGroup.class); cq.where(cb.and(preparePredicatesSystemGroups(cb, from, cq.subquery(Long.class), statuses, deleted, - uuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, + uuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, includeHistory).toArray(new Predicate[0]))); cq.select(cb.count(from)); @@ -118,13 +120,14 @@ public class SystemGroupRepository { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @return list of system groups */ public List<SystemGroup> readSystemGroups(Status status, Boolean deleted, - String uuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description) { + String uuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who) { return readSystemGroups(status != null ? new Status[] {status} : null, deleted, - uuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, + uuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, Boolean.FALSE, null, null, null, null); } @@ -139,6 +142,7 @@ public class SystemGroupRepository { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @param orderBy order by * @param isAsc is ascending * @param offset offset @@ -146,10 +150,10 @@ public class SystemGroupRepository { * @return list of system groups */ public List<SystemGroup> readSystemGroups(Status[] statuses, Boolean deleted, - String uuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, + String uuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, FieldStructure orderBy, Boolean isAsc, Integer offset, Integer limit) { return readSystemGroups(statuses, deleted, - uuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, + uuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, Boolean.FALSE, orderBy, isAsc, offset, limit); } @@ -164,6 +168,7 @@ public class SystemGroupRepository { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @param includeHistory include history * @param orderBy order by * @param isAsc is ascending @@ -172,7 +177,7 @@ public class SystemGroupRepository { * @return list of system groups */ public List<SystemGroup> readSystemGroups(Status[] statuses, Boolean deleted, - String uuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, + String uuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, Boolean includeHistory, FieldStructure orderBy, Boolean isAsc, Integer offset, Integer limit) { // where @@ -189,7 +194,7 @@ public class SystemGroupRepository { Root<SystemGroup> from = cq.from(SystemGroup.class); cq.where(cb.and(preparePredicatesSystemGroups(cb, from, cq.subquery(Long.class), statuses, deleted, - uuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, + uuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, includeHistory).toArray(new Predicate[0]))); cq.select(from); @@ -252,11 +257,12 @@ public class SystemGroupRepository { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @param includeHistory include history * @return list of predicates */ private List<Predicate> preparePredicatesSystemGroups(CriteriaBuilder cb, Root<SystemGroup> from, Subquery<Long> sub, Status[] statuses, Boolean deleted, - String uuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, + String uuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, Boolean includeHistory) { List<Predicate> predicates = new ArrayList<>(); @@ -332,10 +338,140 @@ public class SystemGroupRepository { if (!StringUtils.isEmpty(description)) { predicates.add(cb.and(cb.like(from.get(NameStructure.FIELD_DESCRIPTION), RepositoryUtil.preparePattern(description)))); } + if (!StringUtils.isEmpty(who)) { + predicates.add(cb.and(cb.like(from.get(NameStructure.FIELD_REQUESTED_BY), RepositoryUtil.preparePattern(who)))); + } return predicates; } + /** + * Count system groups history. + * + * @param uuid uuid + * @param name name + * @param mnemonic mnemonic + * @param mnemonicEquivalence mnemonic equivalence + * @param mnemonicPath mnemonic path + * @param description description + * @param who who + * @return count of system groups + */ + public Long countSystemGroupsHistory( + String uuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who) { + + // note + // deleted - null + // includeHistory - true + // where + // queryFields, queryValues + + CriteriaBuilder cb = em.getCriteriaBuilder(); + CriteriaQuery<Long> cq = cb.createQuery(Long.class); + Root<SystemGroup> from = cq.from(SystemGroup.class); + + Subquery<String> sub = cq.subquery(String.class); + Root<SystemGroup> fromSub = sub.from(SystemGroup.class); + sub.where(cb.and(preparePredicatesSystemGroups(cb, fromSub, null, null, null, + uuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, + Boolean.TRUE).toArray(new Predicate[0]))); + sub.select(fromSub.get(NameStructure.FIELD_UUID)); + + cq.where(cb.and(cb.in(from.get(NameStructure.FIELD_UUID)).value(sub))); + cq.select(cb.count(from)); + + return em.createQuery(cq).getSingleResult(); + } + + /** + * Find system groups history. + * + * @param uuid uuid + * @param name name + * @param mnemonic mnemonic + * @param mnemonicEquivalence mnemonic equivalence + * @param mnemonicPath mnemonic path + * @param description description + * @param who who + * @param orderBy order by + * @param isAsc is ascending + * @param offset offset + * @param limit limit + * @return list of system groups + */ + public List<SystemGroup> readSystemGroupsHistory( + String uuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, + FieldStructure orderBy, Boolean isAsc, Integer offset, Integer limit) { + + // note + // deleted - null + // includeHistory - true + // where + // queryFields, queryValues + // order + // orderBy, isAsc + // paging + // offset, limit + + CriteriaBuilder cb = em.getCriteriaBuilder(); + CriteriaQuery<SystemGroup> cq = cb.createQuery(SystemGroup.class); + Root<SystemGroup> from = cq.from(SystemGroup.class); + + Subquery<String> sub = cq.subquery(String.class); + Root<SystemGroup> fromSub = sub.from(SystemGroup.class); + sub.where(cb.and(preparePredicatesSystemGroups(cb, fromSub, null, null, null, + uuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, + Boolean.TRUE).toArray(new Predicate[0]))); + sub.select(fromSub.get(NameStructure.FIELD_UUID)); + + cq.where(cb.and(cb.in(from.get(NameStructure.FIELD_UUID)).value(sub))); + cq.select(from); + + if (orderBy != null) { + if (BooleanUtils.toBoolean(isAsc)) { + if (FieldStructure.NAME.equals(orderBy)) { + cq.orderBy(cb.asc(from.get(Structure.FIELD_NAME))); + } else if (FieldStructure.MNEMONIC.equals(orderBy)) { + cq.orderBy(cb.asc(from.get(Structure.FIELD_MNEMONIC))); + } else if (FieldStructure.MNEMONICEQUIVALENCE.equals(orderBy)) { + cq.orderBy(cb.asc(from.get(Structure.FIELD_MNEMONIC_EQUIVALENCE))); + } else if (FieldStructure.MNEMONICPATH.equals(orderBy)) { + cq.orderBy(cb.asc(from.get(Structure.FIELD_MNEMONIC))); + } else if (FieldStructure.DESCRIPTION.equals(orderBy)) { + cq.orderBy(cb.asc(from.get(NameStructure.FIELD_DESCRIPTION))); + } else if (FieldStructure.WHEN.equals(orderBy)) { + cq.orderBy(cb.asc(from.get(NameStructure.FIELD_REQUESTED))); + } else { + cq.orderBy(cb.asc(from.get(NameStructure.FIELD_UUID)), cb.asc(from.get(Persistable.FIELD_ID))); + } + } else { + if (FieldStructure.NAME.equals(orderBy)) { + cq.orderBy(cb.desc(from.get(Structure.FIELD_NAME))); + } else if (FieldStructure.MNEMONIC.equals(orderBy)) { + cq.orderBy(cb.desc(from.get(Structure.FIELD_MNEMONIC))); + } else if (FieldStructure.MNEMONICEQUIVALENCE.equals(orderBy)) { + cq.orderBy(cb.desc(from.get(Structure.FIELD_MNEMONIC_EQUIVALENCE))); + } else if (FieldStructure.MNEMONICPATH.equals(orderBy)) { + cq.orderBy(cb.desc(from.get(Structure.FIELD_MNEMONIC))); + } else if (FieldStructure.DESCRIPTION.equals(orderBy)) { + cq.orderBy(cb.desc(from.get(NameStructure.FIELD_DESCRIPTION))); + } else if (FieldStructure.WHEN.equals(orderBy)) { + cq.orderBy(cb.desc(from.get(NameStructure.FIELD_REQUESTED))); + } else { + cq.orderBy(cb.desc(from.get(NameStructure.FIELD_UUID)), cb.desc(from.get(Persistable.FIELD_ID))); + } + } + } + + TypedQuery<SystemGroup> query = em.createQuery(cq); + if (offset != null && limit != null) { + query.setFirstResult(offset * limit); + query.setMaxResults(limit); + } + + return query.getResultList(); + } + /** * Persist system group into persistence context. * diff --git a/src/main/java/org/openepics/names/repository/SystemRepository.java b/src/main/java/org/openepics/names/repository/SystemRepository.java index 48761e12ac0f2135b16171456ef2f496bee8eaff..5ef2fe305d5c9ce80c235af3bae23354de7494de 100644 --- a/src/main/java/org/openepics/names/repository/SystemRepository.java +++ b/src/main/java/org/openepics/names/repository/SystemRepository.java @@ -64,12 +64,13 @@ public class SystemRepository { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @return count of systems */ public Long countSystems(Status[] statuses, Boolean deleted, - String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description) { + String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who) { return countSystems(statuses, deleted, - uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, + uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, Boolean.FALSE); } @@ -85,11 +86,12 @@ public class SystemRepository { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @param includeHistory include history * @return count of systems */ public Long countSystems(Status[] statuses, Boolean deleted, - String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, + String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, Boolean includeHistory) { // note @@ -104,7 +106,7 @@ public class SystemRepository { Root<System> from = cq.from(System.class); cq.where(cb.and(preparePredicatesSystems(cb, from, cq.subquery(Long.class), statuses, deleted, - uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, + uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, includeHistory).toArray(new Predicate[0]))); cq.select(cb.count(from)); @@ -123,13 +125,14 @@ public class SystemRepository { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @return list of systems */ public List<System> readSystems(Status status, Boolean deleted, - String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description) { + String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who) { return readSystems(status != null ? new Status[] {status} : null, deleted, - uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, + uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, Boolean.FALSE, null, null, null, null); } @@ -145,6 +148,7 @@ public class SystemRepository { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @param orderBy order by * @param isAsc is ascending * @param offset offset @@ -152,10 +156,10 @@ public class SystemRepository { * @return list of systems */ public List<System> readSystems(Status[] statuses, Boolean deleted, - String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, + String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, FieldStructure orderBy, Boolean isAsc, Integer offset, Integer limit) { return readSystems(statuses, deleted, - uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, + uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, Boolean.FALSE, orderBy, isAsc, offset, limit); } @@ -171,6 +175,7 @@ public class SystemRepository { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @param includeHistory include history * @param orderBy order by * @param isAsc is ascending @@ -179,7 +184,7 @@ public class SystemRepository { * @return list of systems */ public List<System> readSystems(Status[] statuses, Boolean deleted, - String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, + String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, Boolean includeHistory, FieldStructure orderBy, Boolean isAsc, Integer offset, Integer limit) { // note @@ -198,7 +203,7 @@ public class SystemRepository { Root<System> from = cq.from(System.class); cq.where(cb.and(preparePredicatesSystems(cb, from, cq.subquery(Long.class), statuses, deleted, - uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, + uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, includeHistory).toArray(new Predicate[0]))); cq.select(from); @@ -262,11 +267,12 @@ public class SystemRepository { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @param includeHistory include history * @return list of predicates */ private List<Predicate> preparePredicatesSystems(CriteriaBuilder cb, Root<System> from, Subquery<Long> sub, Status[] statuses, Boolean deleted, - String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, + String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, Boolean includeHistory) { List<Predicate> predicates = new ArrayList<>(); @@ -345,10 +351,144 @@ public class SystemRepository { if (!StringUtils.isEmpty(description)) { predicates.add(cb.and(cb.like(from.get(NameStructure.FIELD_DESCRIPTION), RepositoryUtil.preparePattern(description)))); } + if (!StringUtils.isEmpty(who)) { + predicates.add(cb.and(cb.like(from.get(NameStructure.FIELD_REQUESTED_BY), RepositoryUtil.preparePattern(who)))); + } return predicates; } + /** + * Count systems history. + * + * @param uuid uuid + * @param parentUuid parent uuid + * @param name name + * @param mnemonic mnemonic + * @param mnemonicEquivalence mnemonic equivalence + * @param mnemonicPath mnemonic path + * @param description description + * @param who who + * @return count of systems + */ + public Long countSystemsHistory( + String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who) { + + // note + // use of function for mnemonic path + // deleted - null + // includeHistory - true + // where + // queryFields, queryValues + + CriteriaBuilder cb = em.getCriteriaBuilder(); + CriteriaQuery<Long> cq = cb.createQuery(Long.class); + Root<System> from = cq.from(System.class); + + Subquery<String> sub = cq.subquery(String.class); + Root<System> fromSub = sub.from(System.class); + sub.where(cb.and(preparePredicatesSystems(cb, fromSub, null, null, null, + uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, + Boolean.TRUE).toArray(new Predicate[0]))); + sub.select(fromSub.get(NameStructure.FIELD_UUID)); + + cq.where(cb.and(cb.in(from.get(NameStructure.FIELD_UUID)).value(sub))); + cq.select(cb.count(from)); + + return em.createQuery(cq).getSingleResult(); + } + + /** + * Find systems history. + * + * @param uuid uuid + * @param parentUuid parent uuid + * @param name name + * @param mnemonic mnemonic + * @param mnemonicEquivalence mnemonic equivalence + * @param mnemonicPath mnemonic path + * @param description description + * @param who who + * @param orderBy order by + * @param isAsc is ascending + * @param offset offset + * @param limit limit + * @return list of systems + */ + public List<System> readSystemsHistory( + String uuid, String parentUuid, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, + FieldStructure orderBy, Boolean isAsc, Integer offset, Integer limit) { + + // note + // use of function for mnemonic path + // deleted - null + // includeHistory - true + // where + // queryFields, queryValues + // order + // orderBy, isAsc + // paging + // offset, limit + + CriteriaBuilder cb = em.getCriteriaBuilder(); + CriteriaQuery<System> cq = cb.createQuery(System.class); + Root<System> from = cq.from(System.class); + + Subquery<String> sub = cq.subquery(String.class); + Root<System> fromSub = sub.from(System.class); + sub.where(cb.and(preparePredicatesSystems(cb, fromSub, null, null, null, + uuid, parentUuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, + Boolean.TRUE).toArray(new Predicate[0]))); + sub.select(fromSub.get(NameStructure.FIELD_UUID)); + + cq.where(cb.and(cb.in(from.get(NameStructure.FIELD_UUID)).value(sub))); + cq.select(from); + + if (orderBy != null) { + if (BooleanUtils.toBoolean(isAsc)) { + if (FieldStructure.NAME.equals(orderBy)) { + cq.orderBy(cb.asc(from.get(Structure.FIELD_NAME))); + } else if (FieldStructure.MNEMONIC.equals(orderBy)) { + cq.orderBy(cb.asc(from.get(Structure.FIELD_MNEMONIC))); + } else if (FieldStructure.MNEMONICEQUIVALENCE.equals(orderBy)) { + cq.orderBy(cb.asc(from.get(Structure.FIELD_MNEMONIC_EQUIVALENCE))); + } else if (FieldStructure.MNEMONICPATH.equals(orderBy)) { + cq.orderBy(cb.asc(cb.function(System.FUNCTION_GET_MNEMONIC_PATH_SYSTEM, String.class, from.get(NameStructure.FIELD_UUID)))); + } else if (FieldStructure.DESCRIPTION.equals(orderBy)) { + cq.orderBy(cb.asc(from.get(NameStructure.FIELD_DESCRIPTION))); + } else if (FieldStructure.WHEN.equals(orderBy)) { + cq.orderBy(cb.asc(from.get(NameStructure.FIELD_REQUESTED))); + } else { + cq.orderBy(cb.asc(from.get(NameStructure.FIELD_UUID)), cb.asc(from.get(Persistable.FIELD_ID))); + } + } else { + if (FieldStructure.NAME.equals(orderBy)) { + cq.orderBy(cb.desc(from.get(Structure.FIELD_NAME))); + } else if (FieldStructure.MNEMONIC.equals(orderBy)) { + cq.orderBy(cb.desc(from.get(Structure.FIELD_MNEMONIC))); + } else if (FieldStructure.MNEMONICEQUIVALENCE.equals(orderBy)) { + cq.orderBy(cb.desc(from.get(Structure.FIELD_MNEMONIC_EQUIVALENCE))); + } else if (FieldStructure.MNEMONICPATH.equals(orderBy)) { + cq.orderBy(cb.desc(cb.function(System.FUNCTION_GET_MNEMONIC_PATH_SYSTEM, String.class, from.get(NameStructure.FIELD_UUID)))); + } else if (FieldStructure.DESCRIPTION.equals(orderBy)) { + cq.orderBy(cb.desc(from.get(NameStructure.FIELD_DESCRIPTION))); + } else if (FieldStructure.WHEN.equals(orderBy)) { + cq.orderBy(cb.desc(from.get(NameStructure.FIELD_REQUESTED))); + } else { + cq.orderBy(cb.desc(from.get(NameStructure.FIELD_UUID)), cb.desc(from.get(Persistable.FIELD_ID))); + } + } + } + + TypedQuery<System> query = em.createQuery(cq); + if (offset != null && limit != null) { + query.setFirstResult(offset * limit); + query.setMaxResults(limit); + } + + return query.getResultList(); + } + /** * Persist system into persistence context. * diff --git a/src/main/java/org/openepics/names/rest/api/v1/IStructures.java b/src/main/java/org/openepics/names/rest/api/v1/IStructures.java index 40773951a1a22c391c6a6232bf31e0530f5644b7..c22d17a9cd01092ced007769d1ff40dddb752679 100644 --- a/src/main/java/org/openepics/names/rest/api/v1/IStructures.java +++ b/src/main/java/org/openepics/names/rest/api/v1/IStructures.java @@ -92,39 +92,40 @@ public interface IStructures { who (String) Methods - create POST /structures - createStructures (List<StructureElementCommandCreate>) - create POST /structures/upload - createStructures (MultipartFile) + create POST /structures - createStructures + create POST /structures/upload - createStructures upload Excel file ---------------------------------------------------------------------------------------------------- - read GET /structures/{type} - readStructures (Type, Status[], Boolean, String, String, String, String, String, String, String, FieldStructure, Boolean, Integer, Integer) - read GET /structures/{type}/download - readStructuresDownload (Type, Status[], Boolean, String, String, String, String, String, String, String, FieldStructure, Boolean, Integer, Integer) - read GET /structures/children/{uuid} - readStructuresChildren (String, Type, Status[], Boolean, String, String, String, String, String, FieldStructure, Boolean, Integer, Integer) - read GET /structures/mnemonic/{mnemonic} - readStructuresMnemonic (String, FieldStructure, Boolean, Integer, Integer, FieldStructure, Boolean, Integer, Integer) - read GET /structures/mnemonicPath/{mnemonicPath} - readStructuresMnemonicPath (String, FieldStructure, Boolean, Integer, Integer, FieldStructure, Boolean, Integer, Integer) - read GET /structures/history/{uuid} - readStructuresHistory (String, Type, FieldStructure, Boolean, Integer, Integer) + read GET /structures/{type} - readStructures + read GET /structures/{type}/download - readStructuresDownload download Excel file + read GET /structures/children/{uuid} - readStructuresChildren + read GET /structures/mnemonic/{mnemonic} - readStructuresMnemonic + read GET /structures/mnemonicPath/{mnemonicPath} - readStructuresMnemonicPath + read GET /structures/history - readStructuresHistory + read GET /structures/history/{uuid} - readStructuresHistory ---------------------------------------------------------------------------------------------------- - read GET /structures/equivalence/{mnemonic} - equivalenceMnemonic (String) - read GET /structures/exists/{type}/{mnemonicPath} - existsStructure (Type, String) - read GET /structures/isValidToCreate/{type}/{mnemonicPath} - isValidToCreateStructure (Type, String) + read GET /structures/equivalence/{mnemonic} - equivalenceMnemonic + read GET /structures/exists/{type}/{mnemonicPath} - existsStructure + read GET /structures/isValidToCreate/{type}/{mnemonicPath} - isValidToCreateStructure ---------------------------------------------------------------------------------------------------- - read GET /structures/validateCreate - validateStructuresCreate (List<StructureElementCommandCreate>) - read GET /structures/validateUpdate - validateStructuresUpdate (List<StructureElementCommandUpdate>) - read GET /structures/validateDelete - validateStructuresDelete (List<StructureElementCommandConfirm>) - read GET /structures/validateApprove - validateStructuresApprove (List<StructureElementCommandConfirm>) - read GET /structures/validateCancel - validateStructuresCancel (List<StructureElementCommandConfirm>) - read GET /structures/validateReject - validateStructuresReject (List<StructureElementCommandConfirm>) + read GET /structures/validateCreate - validateStructuresCreate hidden from Swagger UI + read GET /structures/validateUpdate - validateStructuresUpdate hidden from Swagger UI + read GET /structures/validateDelete - validateStructuresDelete hidden from Swagger UI + read GET /structures/validateApprove - validateStructuresApprove hidden from Swagger UI + read GET /structures/validateCancel - validateStructuresCancel hidden from Swagger UI + read GET /structures/validateReject - validateStructuresReject hidden from Swagger UI ---------------------------------------------------------------------------------------------------- - update PUT /structures - updateStructures (List<StructureElementCommandUpdate>) - update PUT /structures/upload - updateStructures (MultipartFile) + update PUT /structures - updateStructures + update PUT /structures/upload - updateStructures upload Excel file ---------------------------------------------------------------------------------------------------- - delete DELETE /structures - deleteStructures (List<StructureElementCommandConfirm>) - delete DELETE /structures/upload - deleteStructures (MultipartFile) + delete DELETE /structures - deleteStructures + delete DELETE /structures/upload - deleteStructures upload Excel file ---------------------------------------------------------------------------------------------------- - update PATCH /structures/approve - approveStructures (List<StructureElementCommandConfirm>) - update PATCH /structures/approve/upload - approveStructures (MultipartFile) - update PATCH /structures/cancel - cancelStructures (List<StructureElementCommandConfirm>) - update PATCH /structures/cancel/upload - cancelStructures (MultipartFile) - update PATCH /structures/reject - rejectStructures (List<StructureElementCommandConfirm>) - update PATCH /structures/reject/upload - rejectStructures (MultipartFile) + update PATCH /structures/approve - approveStructures + update PATCH /structures/approve/upload - approveStructures upload Excel file + update PATCH /structures/cancel - cancelStructures + update PATCH /structures/cancel/upload - cancelStructures upload Excel file + update PATCH /structures/reject - rejectStructures + update PATCH /structures/reject/upload - rejectStructures upload Excel file Note /upload and /download endpoints handle Excel files @@ -310,6 +311,7 @@ public interface IStructures { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @param orderBy order by field * @param isAsc sort order, ascending or descending * @param page page starting from 0, offset @@ -356,13 +358,14 @@ public interface IStructures { @Parameter(in = ParameterIn.PATH, description = "search by type of structure") @PathVariable("type") Type type, @Parameter(in = ParameterIn.QUERY, description = "search by statuses") @RequestParam(required = false) Status[] statuses, @Parameter(in = ParameterIn.QUERY, description = "if deleted structures are to be included or not, omitted for both deleted and not deleted structures") @RequestParam(required = false) Boolean deleted, - @Parameter(in = ParameterIn.QUERY, description = "search by uuid") @RequestParam(required = false) String uuid, + @Parameter(in = ParameterIn.QUERY, description = "find by uuid") @RequestParam(required = false) String uuid, @Parameter(in = ParameterIn.QUERY, description = "search by parent uuid") @RequestParam(required = false) String parent, @Parameter(in = ParameterIn.QUERY, description = "search by name") @RequestParam(required = false) String name, @Parameter(in = ParameterIn.QUERY, description = "search by mnemonic") @RequestParam(required = false) String mnemonic, @Parameter(in = ParameterIn.QUERY, description = "search by mnemonic equivalence") @RequestParam(required = false) String mnemonicEquivalence, @Parameter(in = ParameterIn.QUERY, description = "search by mnemonic path") @RequestParam(required = false) String mnemonicPath, @Parameter(in = ParameterIn.QUERY, description = "search by description") @RequestParam(required = false) String description, + @Parameter(in = ParameterIn.QUERY, description = "search by who") @RequestParam(required = false) String who, @Parameter(in = ParameterIn.QUERY, description = "order by field") @RequestParam(required = false) FieldStructure orderBy, @Parameter(in = ParameterIn.QUERY, description = "sort order, ascending or descending") @RequestParam(required = false) Boolean isAsc, @Parameter(in = ParameterIn.QUERY, description = "page starting from 0, offset") @RequestParam(required = false, defaultValue = DEFAULT_PAGE) Integer page, @@ -383,6 +386,7 @@ public interface IStructures { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @param orderBy order by field * @param isAsc sort order, ascending or descending * @param page page starting from 0, offset @@ -427,13 +431,14 @@ public interface IStructures { @Parameter(in = ParameterIn.PATH, description = "search by type of structure") @PathVariable("type") Type type, @Parameter(in = ParameterIn.QUERY, description = "search by statuses") @RequestParam(required = false) Status[] statuses, @Parameter(in = ParameterIn.QUERY, description = "if deleted structures are to be included or not, omitted for both deleted and not deleted structures") @RequestParam(required = false) Boolean deleted, - @Parameter(in = ParameterIn.QUERY, description = "search by uuid") @RequestParam(required = false) String uuid, + @Parameter(in = ParameterIn.QUERY, description = "find by uuid") @RequestParam(required = false) String uuid, @Parameter(in = ParameterIn.QUERY, description = "search by parent uuid") @RequestParam(required = false) String parent, @Parameter(in = ParameterIn.QUERY, description = "search by name") @RequestParam(required = false) String name, @Parameter(in = ParameterIn.QUERY, description = "search by mnemonic") @RequestParam(required = false) String mnemonic, @Parameter(in = ParameterIn.QUERY, description = "search by mnemonic equivalence") @RequestParam(required = false) String mnemonicEquivalence, @Parameter(in = ParameterIn.QUERY, description = "search by mnemonic path") @RequestParam(required = false) String mnemonicPath, @Parameter(in = ParameterIn.QUERY, description = "search by description") @RequestParam(required = false) String description, + @Parameter(in = ParameterIn.QUERY, description = "search by who") @RequestParam(required = false) String who, @Parameter(in = ParameterIn.QUERY, description = "order by field") @RequestParam(required = false) FieldStructure orderBy, @Parameter(in = ParameterIn.QUERY, description = "sort order, ascending or descending") @RequestParam(required = false) Boolean isAsc, @Parameter(in = ParameterIn.QUERY, description = "page starting from 0, offset") @RequestParam(required = false, defaultValue = DEFAULT_PAGE) Integer page, @@ -453,6 +458,7 @@ public interface IStructures { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who who * @param orderBy order by field * @param isAsc sort order, ascending or descending * @param page page starting from 0, offset @@ -496,7 +502,7 @@ public interface IStructures { value = "/children/{uuid}", produces = {"application/json"}) public ResponsePageStructureElements readStructuresChildren( - @Parameter(in = ParameterIn.PATH, description = "search by uuid") @PathVariable("uuid") String uuid, + @Parameter(in = ParameterIn.PATH, description = "find by uuid") @PathVariable("uuid") String uuid, @Parameter(in = ParameterIn.QUERY, description = "search by type of structure") @RequestParam(required = false) Type type, @Parameter(in = ParameterIn.QUERY, description = "search by statuses") @RequestParam(required = false) Status[] statuses, @Parameter(in = ParameterIn.QUERY, description = "if deleted structures are to be included or not, omitted for both deleted and not deleted structures") @RequestParam(required = false) Boolean deleted, @@ -505,6 +511,7 @@ public interface IStructures { @Parameter(in = ParameterIn.QUERY, description = "search by mnemonic equivalence") @RequestParam(required = false) String mnemonicEquivalence, @Parameter(in = ParameterIn.QUERY, description = "search by mnemonic path") @RequestParam(required = false) String mnemonicPath, @Parameter(in = ParameterIn.QUERY, description = "search by description") @RequestParam(required = false) String description, + @Parameter(in = ParameterIn.QUERY, description = "search by who") @RequestParam(required = false) String who, @Parameter(in = ParameterIn.QUERY, description = "order by field") @RequestParam(required = false) FieldStructure orderBy, @Parameter(in = ParameterIn.QUERY, description = "sort order, ascending or descending") @RequestParam(required = false) Boolean isAsc, @Parameter(in = ParameterIn.QUERY, description = "page starting from 0, offset") @RequestParam(required = false, defaultValue = DEFAULT_PAGE) Integer page, @@ -618,9 +625,81 @@ public interface IStructures { @Parameter(in = ParameterIn.QUERY, description = "page starting from 0, offset") @RequestParam(required = false, defaultValue = DEFAULT_PAGE) Integer page, @Parameter(in = ParameterIn.QUERY, description = "page size, limit") @RequestParam(required = false, defaultValue = DEFAULT_PAGE_SIZE) Integer pageSize); + /** + * Find history for structure (search). + * History consists of lines of uuid. + * The line of uuid is not broken in retrieving history. If combination of parameters is found in structure entries, the entire lines of uuid are returned. + * Return paged list of structure elements. + * + * @param type type of structure + * @param uuid uuid + * @param parent parent uuid + * @param name name + * @param mnemonic mnemonic + * @param mnemonicEquivalence mnemonic equivalence + * @param description description + * @param who who + * @param orderBy order by field + * @param isAsc sort order, ascending or descending + * @param page page starting from 0, offset + * @param pageSize page size, limit + * @return paged list of structure elements + */ + @Operation( + summary = "Find history for structure (search)", + description = """ + Find history for structure (search). + History consists of lines of uuid. The line of uuid is not broken in retrieving history. If combination of parameters is found in structure entries, the entire lines of uuid are returned. + Return paged array of structure elements. + """ + ) + @ApiResponses(value = { + @ApiResponse( + responseCode = "200", + description = "OK. Return paged array of structure elements.", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = ResponsePageStructureElements.class))), + @ApiResponse( + responseCode = "400", + description = "Bad request. Reason and information such as message, details, field are available.", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = Response.class))), + @ApiResponse( + responseCode = "422", + description = "Unprocessable entity. Reason and information such as message, details, field are available.", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = Response.class))), + @ApiResponse( + responseCode = "500", + description = "Internal server error. Reason and information such as message, details, field are available.", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = Response.class))) + }) + @GetMapping( + value = "/history", + produces = {"application/json"}) + public ResponsePageStructureElements readStructuresHistory( + @Parameter(in = ParameterIn.QUERY, description = "search by type of structure") @RequestParam(required = false) Type type, + @Parameter(in = ParameterIn.QUERY, description = "find by uuid") @RequestParam(required = false) String uuid, + @Parameter(in = ParameterIn.QUERY, description = "search by parent uuid") @RequestParam(required = false) String parent, + @Parameter(in = ParameterIn.QUERY, description = "search by name") @RequestParam(required = false) String name, + @Parameter(in = ParameterIn.QUERY, description = "search by mnemonic") @RequestParam(required = false) String mnemonic, + @Parameter(in = ParameterIn.QUERY, description = "search by mnemonic equivalence") @RequestParam(required = false) String mnemonicEquivalence, + @Parameter(in = ParameterIn.QUERY, description = "search by description") @RequestParam(required = false) String description, + @Parameter(in = ParameterIn.QUERY, description = "search by who") @RequestParam(required = false) String who, + @Parameter(in = ParameterIn.QUERY, description = "order by field") @RequestParam(required = false) FieldStructure orderBy, + @Parameter(in = ParameterIn.QUERY, description = "sort order, ascending or descending") @RequestParam(required = false) Boolean isAsc, + @Parameter(in = ParameterIn.QUERY, description = "page starting from 0, offset") @RequestParam(required = false, defaultValue = DEFAULT_PAGE) Integer page, + @Parameter(in = ParameterIn.QUERY, description = "page size, limit") @RequestParam(required = false, defaultValue = DEFAULT_PAGE_SIZE) Integer pageSize); + /** * Find history for structure by uuid (exact match). * History consists of line of uuid. + * The line of uuid is not broken in retrieving history. If the uuid is found in a structure entry, the entire line of uuid is returned. * Return paged list of structure elements. * * @param uuid uuid @@ -635,7 +714,7 @@ public interface IStructures { summary = "Find history for structure by uuid (exact match)", description = """ Find history for structure by uuid (exact match). - History consists of line of uuid. + History consists of line of uuid. The line of uuid is not broken in retrieving history. If the uuid is found in a structure entry, the entire line of uuid is returned. Return paged array of structure elements. """ ) @@ -669,7 +748,7 @@ public interface IStructures { value = "/history/{uuid}", produces = {"application/json"}) public ResponsePageStructureElements readStructuresHistory( - @Parameter(in = ParameterIn.PATH, description = "search by uuid") @PathVariable("uuid") String uuid, + @Parameter(in = ParameterIn.PATH, description = "find by uuid") @PathVariable("uuid") String uuid, @Parameter(in = ParameterIn.QUERY, description = "search by type of structure") @RequestParam(required = false) Type type, @Parameter(in = ParameterIn.QUERY, description = "order by field") @RequestParam(required = false, defaultValue = DEFAULT_SORT_FIELD_WHEN) FieldStructure orderBy, @Parameter(in = ParameterIn.QUERY, description = "sort order, ascending or descending") @RequestParam(required = false, defaultValue = DEFAULT_SORT_ORDER_ASC) Boolean isAsc, diff --git a/src/main/java/org/openepics/names/rest/controller/ReportController.java b/src/main/java/org/openepics/names/rest/controller/ReportController.java index 5ae9c2d478f643bbdffaca6386fce4a446f1f4b6..ee209e5fd59ad5ada1a7e2714a3cce49e3a95fab 100644 --- a/src/main/java/org/openepics/names/rest/controller/ReportController.java +++ b/src/main/java/org/openepics/names/rest/controller/ReportController.java @@ -171,12 +171,12 @@ public class ReportController { // prepare metrics // read structures - latest // count structures - status - ResponsePageStructureElements structureElementsSystemgroup = structuresService.readStructures(Type.SYSTEMGROUP, null, null, null, null, null, null, null, null, null, Boolean.FALSE, null, null, null, null, StructureChoice.STRUCTURE); - ResponsePageStructureElements structureElementsSystem = structuresService.readStructures(Type.SYSTEM, null, null, null, null, null, null, null, null, null, Boolean.FALSE, null, null, null, null, StructureChoice.STRUCTURE); - ResponsePageStructureElements structureElementsSubsystem = structuresService.readStructures(Type.SUBSYSTEM, null, null, null, null, null, null, null, null, null, Boolean.FALSE, null, null, null, null, StructureChoice.STRUCTURE); - ResponsePageStructureElements structureElementsDiscipline = structuresService.readStructures(Type.DISCIPLINE, null, null, null, null, null, null, null, null, null, Boolean.FALSE, null, null, null, null, StructureChoice.STRUCTURE); - ResponsePageStructureElements structureElementsDevicegroup = structuresService.readStructures(Type.DEVICEGROUP, null, null, null, null, null, null, null, null, null, Boolean.FALSE, null, null, null, null, StructureChoice.STRUCTURE); - ResponsePageStructureElements structureElementsDevicetype = structuresService.readStructures(Type.DEVICETYPE, null, null, null, null, null, null, null, null, null, Boolean.FALSE, null, null, null, null, StructureChoice.STRUCTURE); + ResponsePageStructureElements structureElementsSystemgroup = structuresService.readStructures(Type.SYSTEMGROUP, null, null, null, null, null, null, null, null, null, null, Boolean.FALSE, null, null, null, null, StructureChoice.STRUCTURE); + ResponsePageStructureElements structureElementsSystem = structuresService.readStructures(Type.SYSTEM, null, null, null, null, null, null, null, null, null, null, Boolean.FALSE, null, null, null, null, StructureChoice.STRUCTURE); + ResponsePageStructureElements structureElementsSubsystem = structuresService.readStructures(Type.SUBSYSTEM, null, null, null, null, null, null, null, null, null, null, Boolean.FALSE, null, null, null, null, StructureChoice.STRUCTURE); + ResponsePageStructureElements structureElementsDiscipline = structuresService.readStructures(Type.DISCIPLINE, null, null, null, null, null, null, null, null, null, null, Boolean.FALSE, null, null, null, null, StructureChoice.STRUCTURE); + ResponsePageStructureElements structureElementsDevicegroup = structuresService.readStructures(Type.DEVICEGROUP, null, null, null, null, null, null, null, null, null, null, Boolean.FALSE, null, null, null, null, StructureChoice.STRUCTURE); + ResponsePageStructureElements structureElementsDevicetype = structuresService.readStructures(Type.DEVICETYPE, null, null, null, null, null, null, null, null, null, null, Boolean.FALSE, null, null, null, null, StructureChoice.STRUCTURE); Map<UUID, Long> mapUuidCountSystemGroup = new TreeMap<>(); Map<UUID, Long> mapUuidCountSystem = new TreeMap<>(); diff --git a/src/main/java/org/openepics/names/rest/controller/StructuresController.java b/src/main/java/org/openepics/names/rest/controller/StructuresController.java index 175f8113dd833cf554f2bbbb8dced39f964da2f2..a13916cd0b2c27b4d175dc59b1f53b81bea34145 100644 --- a/src/main/java/org/openepics/names/rest/controller/StructuresController.java +++ b/src/main/java/org/openepics/names/rest/controller/StructuresController.java @@ -153,17 +153,17 @@ public class StructuresController implements IStructures { @Override public ResponsePageStructureElements readStructures(Type type, Status[] statuses, Boolean deleted, - String uuid, String parent, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, + String uuid, String parent, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, FieldStructure orderBy, Boolean isAsc, Integer page, Integer pageSize) { // validate // read structures try { ValidateStructureElementUtil.validateStructuresInputRead(type, statuses, deleted, - uuid, parent, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, + uuid, parent, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, null, orderBy, isAsc, page, pageSize); return structuresService.readStructures(type, statuses, deleted, - uuid, parent, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, + uuid, parent, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, orderBy, isAsc, page, pageSize); } catch (ServiceException e) { logService.logServiceException(LOGGER, Level.WARNING, e); @@ -177,14 +177,14 @@ public class StructuresController implements IStructures { @Override public ResponseEntity<Resource> readStructuresDownload(Type type, Status[] statuses, Boolean deleted, - String uuid, String parent, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, + String uuid, String parent, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, FieldStructure orderBy, Boolean isAsc, Integer page, Integer pageSize) { // validate // read structures // convert to output ResponsePageStructureElements structureElements = readStructures(type, statuses, deleted, - uuid, parent, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, + uuid, parent, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, orderBy, isAsc, page, pageSize); InputStreamResource isr = new InputStreamResource(ExcelUtil.structureElementsToExcel(structureElements)); return ResponseEntity.ok() @@ -195,7 +195,7 @@ public class StructuresController implements IStructures { @Override public ResponsePageStructureElements readStructuresChildren(String uuid, Type type, Status[] statuses, Boolean deleted, - String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, + String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, FieldStructure orderBy, Boolean isAsc, Integer page, Integer pageSize) { // validate // read structures @@ -203,7 +203,7 @@ public class StructuresController implements IStructures { try { ValidateUtil.validateInputUuid(uuid); return structuresService.readStructuresChildren(uuid, type, statuses, deleted, - name, mnemonic, mnemonicEquivalence, mnemonicPath, description, + name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, orderBy, isAsc, page, pageSize); } catch (ServiceException e) { logService.logServiceException(LOGGER, Level.WARNING, e); @@ -253,6 +253,35 @@ public class StructuresController implements IStructures { } } + @Override + public ResponsePageStructureElements readStructuresHistory(Type type, + String uuid, String parent, String name, String mnemonic, String mnemonicEquivalence, String description, String who, + FieldStructure orderBy, Boolean isAsc, Integer page, Integer pageSize) { + // validate + // read names + + try { + ValidateUtil.validateInputAvailable( + !ValidateUtil.areAllNull(uuid, parent, name, mnemonic, mnemonicEquivalence, description, who)); + ValidateStructureElementUtil.validateStructuresInputRead( + null, null, + uuid, parent, name, mnemonic, mnemonicEquivalence, null, description, who, + null, + orderBy, isAsc, + page, pageSize); + return structuresService.readStructuresHistory(type, + uuid, parent, name, mnemonic, mnemonicEquivalence, description, who, + orderBy, isAsc, page, pageSize); + } catch (ServiceException e) { + logService.logServiceException(LOGGER, Level.WARNING, e); + logService.logStackTraceElements(LOGGER, Level.WARNING, e); + throw e; + } catch (Exception e) { + logService.logStackTraceElements(LOGGER, Level.WARNING, e); + throw e; + } + } + @Override public ResponsePageStructureElements readStructuresHistory(String uuid, Type type, FieldStructure orderBy, Boolean isAsc, Integer page, Integer pageSize) { diff --git a/src/main/java/org/openepics/names/service/DeviceGroupService.java b/src/main/java/org/openepics/names/service/DeviceGroupService.java index edea5ab7cde2bdafa06576fc9ed9a580adec573b..3f94ae75ca7a5f011f2380609fd73bc721a2f2aa 100644 --- a/src/main/java/org/openepics/names/service/DeviceGroupService.java +++ b/src/main/java/org/openepics/names/service/DeviceGroupService.java @@ -171,7 +171,7 @@ public class DeviceGroupService { // uuid, comment // find - List<DeviceGroup> deviceGroups = deviceGroupRepository.readDeviceGroups(Status.APPROVED, Boolean.FALSE, structureElementCommand.getUuid().toString(), null, null, null, null, null, null); + List<DeviceGroup> deviceGroups = deviceGroupRepository.readDeviceGroups(Status.APPROVED, Boolean.FALSE, structureElementCommand.getUuid().toString(), null, null, null, null, null, null, null); if (ValidateUtil.isNullOrNotSize(deviceGroups, 1)) { return null; } @@ -224,7 +224,7 @@ public class DeviceGroupService { String uuid = structureElementCommand.getUuid().toString(); // find - List<DeviceGroup> deviceGroups = deviceGroupRepository.readDeviceGroups(Status.APPROVED, Boolean.FALSE, uuid, null, null, null, null, null, null); + List<DeviceGroup> deviceGroups = deviceGroupRepository.readDeviceGroups(Status.APPROVED, Boolean.FALSE, uuid, null, null, null, null, null, null, null); DeviceGroup deviceGroup = null; if (ValidateUtil.isSize(deviceGroups, 1)) { deviceGroup = deviceGroups.get(0); @@ -235,7 +235,7 @@ public class DeviceGroupService { } // find - deviceGroups = deviceGroupRepository.readDeviceGroups(Status.PENDING, null, uuid, null, null, null, null, null, null); + deviceGroups = deviceGroupRepository.readDeviceGroups(Status.PENDING, null, uuid, null, null, null, null, null, null, null); if (ValidateUtil.isNullOrNotSize(deviceGroups, 1)) { return null; } @@ -294,7 +294,7 @@ public class DeviceGroupService { String uuid = structureElementCommand.getUuid().toString(); // find - List<DeviceGroup> deviceGroups = deviceGroupRepository.readDeviceGroups(Status.PENDING, null, uuid, null, null, null, null, null, null); + List<DeviceGroup> deviceGroups = deviceGroupRepository.readDeviceGroups(Status.PENDING, null, uuid, null, null, null, null, null, null, null); if (ValidateUtil.isNullOrNotSize(deviceGroups, 1)) { return null; } @@ -335,7 +335,7 @@ public class DeviceGroupService { String uuid = structureElementCommand.getUuid().toString(); // find - List<DeviceGroup> deviceGroups = deviceGroupRepository.readDeviceGroups(Status.PENDING, null, uuid, null, null, null, null, null, null); + List<DeviceGroup> deviceGroups = deviceGroupRepository.readDeviceGroups(Status.PENDING, null, uuid, null, null, null, null, null, null, null); if (ValidateUtil.isNullOrNotSize(deviceGroups, 1)) { return null; } diff --git a/src/main/java/org/openepics/names/service/DeviceTypeService.java b/src/main/java/org/openepics/names/service/DeviceTypeService.java index 194a347295cb84280934698f19e94a652d152aa3..5fcbce5e791f383b47c402b8a2948cbd61c945e0 100644 --- a/src/main/java/org/openepics/names/service/DeviceTypeService.java +++ b/src/main/java/org/openepics/names/service/DeviceTypeService.java @@ -164,7 +164,7 @@ public class DeviceTypeService { // uuid, comment // find - List<DeviceType> deviceTypes = deviceTypeRepository.readDeviceTypes(Status.APPROVED, Boolean.FALSE, structureElementCommand.getUuid().toString(), null, null, null, null, null, null); + List<DeviceType> deviceTypes = deviceTypeRepository.readDeviceTypes(Status.APPROVED, Boolean.FALSE, structureElementCommand.getUuid().toString(), null, null, null, null, null, null, null); if (ValidateUtil.isNullOrNotSize(deviceTypes, 1)) { return null; } @@ -217,7 +217,7 @@ public class DeviceTypeService { String uuid = structureElementCommand.getUuid().toString(); // find - List<DeviceType> deviceTypes = deviceTypeRepository.readDeviceTypes(Status.APPROVED, Boolean.FALSE, uuid, null, null, null, null, null, null); + List<DeviceType> deviceTypes = deviceTypeRepository.readDeviceTypes(Status.APPROVED, Boolean.FALSE, uuid, null, null, null, null, null, null, null); DeviceType deviceType = null; if (ValidateUtil.isSize(deviceTypes, 1)) { deviceType = deviceTypes.get(0); @@ -228,7 +228,7 @@ public class DeviceTypeService { } // find - deviceTypes = deviceTypeRepository.readDeviceTypes(Status.PENDING, null, uuid, null, null, null, null, null, null); + deviceTypes = deviceTypeRepository.readDeviceTypes(Status.PENDING, null, uuid, null, null, null, null, null, null, null); if (ValidateUtil.isNullOrNotSize(deviceTypes, 1)) { return null; } @@ -276,7 +276,7 @@ public class DeviceTypeService { String uuid = structureElementCommand.getUuid().toString(); - List<DeviceType> deviceTypes = deviceTypeRepository.readDeviceTypes(Status.PENDING, null, uuid, null, null, null, null, null, null); + List<DeviceType> deviceTypes = deviceTypeRepository.readDeviceTypes(Status.PENDING, null, uuid, null, null, null, null, null, null, null); if (ValidateUtil.isNullOrNotSize(deviceTypes, 1)) { return null; } @@ -317,7 +317,7 @@ public class DeviceTypeService { String uuid = structureElementCommand.getUuid().toString(); // find - List<DeviceType> deviceTypes = deviceTypeRepository.readDeviceTypes(Status.PENDING, null, uuid, null, null, null, null, null, null); + List<DeviceType> deviceTypes = deviceTypeRepository.readDeviceTypes(Status.PENDING, null, uuid, null, null, null, null, null, null, null); if (ValidateUtil.isNullOrNotSize(deviceTypes, 1)) { return null; } diff --git a/src/main/java/org/openepics/names/service/DisciplineService.java b/src/main/java/org/openepics/names/service/DisciplineService.java index cc7a602159aac010b3ed373ee603442d836f7340..757ae531e6c9d95b954a14bee0850748c002c415 100644 --- a/src/main/java/org/openepics/names/service/DisciplineService.java +++ b/src/main/java/org/openepics/names/service/DisciplineService.java @@ -174,7 +174,7 @@ public class DisciplineService { // uuid, comment // find - List<Discipline> disciplines = disciplineRepository.readDisciplines(Status.APPROVED, Boolean.FALSE, structureElementCommand.getUuid().toString(), null, null, null, null, null); + List<Discipline> disciplines = disciplineRepository.readDisciplines(Status.APPROVED, Boolean.FALSE, structureElementCommand.getUuid().toString(), null, null, null, null, null, null); if (ValidateUtil.isNullOrNotSize(disciplines, 1)) { return null; } @@ -226,7 +226,7 @@ public class DisciplineService { String uuid = structureElementCommand.getUuid().toString(); - List<Discipline> disciplines = disciplineRepository.readDisciplines(Status.APPROVED, Boolean.FALSE, uuid, null, null, null, null, null); + List<Discipline> disciplines = disciplineRepository.readDisciplines(Status.APPROVED, Boolean.FALSE, uuid, null, null, null, null, null, null); Discipline discipline = null; if (ValidateUtil.isSize(disciplines, 1)) { discipline = disciplines.get(0); @@ -237,7 +237,7 @@ public class DisciplineService { } // find - disciplines = disciplineRepository.readDisciplines(Status.PENDING, null, uuid, null, null, null, null, null); + disciplines = disciplineRepository.readDisciplines(Status.PENDING, null, uuid, null, null, null, null, null, null); if (ValidateUtil.isNullOrNotSize(disciplines, 1)) { return null; } @@ -298,7 +298,7 @@ public class DisciplineService { String uuid = structureElementCommand.getUuid().toString(); // find - List<Discipline> disciplines = disciplineRepository.readDisciplines(Status.PENDING, null, uuid, null, null, null, null, null); + List<Discipline> disciplines = disciplineRepository.readDisciplines(Status.PENDING, null, uuid, null, null, null, null, null, null); if (ValidateUtil.isNullOrNotSize(disciplines, 1)) { return null; } @@ -339,7 +339,7 @@ public class DisciplineService { String uuid = structureElementCommand.getUuid().toString(); // find - List<Discipline> disciplines = disciplineRepository.readDisciplines(Status.PENDING, null, uuid, null, null, null, null, null); + List<Discipline> disciplines = disciplineRepository.readDisciplines(Status.PENDING, null, uuid, null, null, null, null, null, null); if (ValidateUtil.isNullOrNotSize(disciplines, 1)) { return null; } diff --git a/src/main/java/org/openepics/names/service/StructuresService.java b/src/main/java/org/openepics/names/service/StructuresService.java index fb94f92725af2792a1e20ed2e268b612d958810f..6b4de7ac6149c458e826d21594e4af18ffb9bbf1 100644 --- a/src/main/java/org/openepics/names/service/StructuresService.java +++ b/src/main/java/org/openepics/names/service/StructuresService.java @@ -218,15 +218,15 @@ public class StructuresService { // ---------------------------------------------------------------------------------------------------- public ResponsePageStructureElements readStructures(Type type, Status[] statuses, Boolean deleted, - String uuid, String parent, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, + String uuid, String parent, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, FieldStructure orderBy, Boolean isAsc, Integer offset, Integer limit) { return readStructures(type, statuses, deleted, - uuid, parent, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, + uuid, parent, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, Boolean.FALSE, orderBy, isAsc, offset, limit, StructureChoice.STRUCTURE); } public ResponsePageStructureElements readStructures(Type type, Status[] statuses, Boolean deleted, - String uuid, String parent, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, + String uuid, String parent, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, Boolean includeHistory, FieldStructure orderBy, Boolean isAsc, Integer offset, Integer limit, StructureChoice structureChoice) { // validation outside method @@ -244,6 +244,7 @@ public class StructuresService { LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES, "mnemonicEquivalence", mnemonicEquivalence)); LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES, "mnemonicPath", mnemonicPath)); LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES, "description", description)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES, "who", who)); LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES, "includeHistory", includeHistory)); LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES, "orderBy", orderBy)); LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES, "isAsc", isAsc)); @@ -261,69 +262,71 @@ public class StructuresService { HolderSystemDeviceStructure holderStructure = new HolderSystemDeviceStructure(holderIRepositories); final List<StructureElement> structureElements = Lists.newArrayList(); - Long totalCount = null; - if (Type.SYSTEMGROUP.equals(type)) { - // system group has no parent uuid - List<SystemGroup> systemGroups = null; - if (StringUtils.isEmpty(parent)) { - systemGroups = holderRepositories.systemGroupRepository().readSystemGroups(statuses, deleted, - uuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, - includeHistory, orderBy, isAsc, offset, limit); - totalCount = holderRepositories.systemGroupRepository().countSystemGroups(statuses, deleted, - uuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, - includeHistory); - } else { - systemGroups = Lists.newArrayList(); - totalCount = 0L; - } - structureElements.addAll(StructureElementUtil.getStructureElementsForSystemGroups(systemGroups, holderStructure, structureChoice)); - } else if (Type.SYSTEM.equals(type)) { - List<System> systems = holderRepositories.systemRepository().readSystems(statuses, deleted, - uuid, parent, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, - includeHistory, orderBy, isAsc, offset, limit); - totalCount = holderRepositories.systemRepository().countSystems(statuses, deleted, - uuid, parent, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, - includeHistory); - structureElements.addAll(StructureElementUtil.getStructureElementsForSystems(systems, holderStructure, structureChoice)); - } else if (Type.SUBSYSTEM.equals(type)) { - List<Subsystem> subsystems = holderRepositories.subsystemRepository().readSubsystems(statuses, deleted, - uuid, parent, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, - includeHistory, orderBy, isAsc, offset, limit); - totalCount = holderRepositories.subsystemRepository().countSubsystems(statuses, deleted, - uuid, parent, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, - includeHistory); - structureElements.addAll(StructureElementUtil.getStructureElementsForSubsystems(subsystems, holderStructure, structureChoice)); - } else if (Type.DISCIPLINE.equals(type)) { - // discipline has no parent uuid - List<Discipline> disciplines = null; - if (StringUtils.isEmpty(parent)) { - disciplines = holderRepositories.disciplineRepository().readDisciplines(statuses, deleted, - uuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, - includeHistory, orderBy, isAsc, offset, limit); - totalCount = holderRepositories.disciplineRepository().countDisciplines(statuses, deleted, - uuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, - includeHistory); - } else { - disciplines = Lists.newArrayList(); - totalCount = 0L; + Long totalCount = 0L; + + // systemgroup and discipline do not have parent uuid + if (StringUtils.isEmpty(parent) || ValidateUtil.isAnyEqual(type, Type.SYSTEM, Type.SUBSYSTEM, Type.DEVICEGROUP, Type.DEVICETYPE)) { + if (Type.SYSTEMGROUP.equals(type)) { + List<SystemGroup> systemGroups = null; + if (Boolean.TRUE.equals(includeHistory)) { + systemGroups = holderRepositories.systemGroupRepository().readSystemGroupsHistory(uuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, orderBy, isAsc, offset, limit); + totalCount = holderRepositories.systemGroupRepository().countSystemGroupsHistory(uuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who); + } else { + systemGroups = holderRepositories.systemGroupRepository().readSystemGroups(statuses, deleted, uuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, includeHistory, orderBy, isAsc, offset, limit); + totalCount = holderRepositories.systemGroupRepository().countSystemGroups(statuses, deleted, uuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, includeHistory); + } + structureElements.addAll(StructureElementUtil.getStructureElementsForSystemGroups(systemGroups, holderStructure, structureChoice)); + } else if (Type.SYSTEM.equals(type)) { + List<System> systems = null; + if (Boolean.TRUE.equals(includeHistory)) { + systems = holderRepositories.systemRepository().readSystemsHistory(uuid, parent, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, orderBy, isAsc, offset, limit); + totalCount = holderRepositories.systemRepository().countSystemsHistory(uuid, parent, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who); + } else { + systems = holderRepositories.systemRepository().readSystems(statuses, deleted, uuid, parent, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, includeHistory, orderBy, isAsc, offset, limit); + totalCount = holderRepositories.systemRepository().countSystems(statuses, deleted, uuid, parent, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, includeHistory); + } + structureElements.addAll(StructureElementUtil.getStructureElementsForSystems(systems, holderStructure, structureChoice)); + } else if (Type.SUBSYSTEM.equals(type)) { + List<Subsystem> subsystems = null; + if (Boolean.TRUE.equals(includeHistory)) { + subsystems = holderRepositories.subsystemRepository().readSubsystemsHistory(uuid, parent, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, orderBy, isAsc, offset, limit); + totalCount = holderRepositories.subsystemRepository().countSubsystemsHistory(uuid, parent, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who); + } else { + subsystems = holderRepositories.subsystemRepository().readSubsystems(statuses, deleted, uuid, parent, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, includeHistory, orderBy, isAsc, offset, limit); + totalCount = holderRepositories.subsystemRepository().countSubsystems(statuses, deleted, uuid, parent, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, includeHistory); + } + structureElements.addAll(StructureElementUtil.getStructureElementsForSubsystems(subsystems, holderStructure, structureChoice)); + } else if (Type.DISCIPLINE.equals(type)) { + List<Discipline> disciplines = null; + if (Boolean.TRUE.equals(includeHistory)) { + disciplines = holderRepositories.disciplineRepository().readDisciplinesHistory(uuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, orderBy, isAsc, offset, limit); + totalCount = holderRepositories.disciplineRepository().countDisciplinesHistory(uuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who); + } else { + disciplines = holderRepositories.disciplineRepository().readDisciplines(statuses, deleted, uuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, includeHistory, orderBy, isAsc, offset, limit); + totalCount = holderRepositories.disciplineRepository().countDisciplines(statuses, deleted, uuid, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, includeHistory); + } + structureElements.addAll(StructureElementUtil.getStructureElementsForDisciplines(disciplines, holderStructure, structureChoice)); + } else if (Type.DEVICEGROUP.equals(type)) { + List<DeviceGroup> deviceGroups = null; + if (Boolean.TRUE.equals(includeHistory)) { + deviceGroups = holderRepositories.deviceGroupRepository().readDeviceGroupsHistory(uuid, parent, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, orderBy, isAsc, offset, limit); + totalCount = holderRepositories.deviceGroupRepository().countDeviceGroupsHistory(uuid, parent, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who); + } else { + deviceGroups = holderRepositories.deviceGroupRepository().readDeviceGroups(statuses, deleted, uuid, parent, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, includeHistory, orderBy, isAsc, offset, limit); + totalCount = holderRepositories.deviceGroupRepository().countDeviceGroups(statuses, deleted, uuid, parent, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, includeHistory); + } + structureElements.addAll(StructureElementUtil.getStructureElementsForDeviceGroups(deviceGroups, holderStructure, structureChoice)); + } else if (Type.DEVICETYPE.equals(type)) { + List<DeviceType> deviceTypes = null; + if (Boolean.TRUE.equals(includeHistory)) { + deviceTypes = holderRepositories.deviceTypeRepository().readDeviceTypesHistory(uuid, parent, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, orderBy, isAsc, offset, limit); + totalCount = holderRepositories.deviceTypeRepository().countDeviceTypesHistory(uuid, parent, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who); + } else { + deviceTypes = holderRepositories.deviceTypeRepository().readDeviceTypes(statuses, deleted, uuid, parent, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, includeHistory, orderBy, isAsc, offset, limit); + totalCount = holderRepositories.deviceTypeRepository().countDeviceTypes(statuses, deleted, uuid, parent, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, includeHistory); + } + structureElements.addAll(StructureElementUtil.getStructureElementsForDeviceTypes(deviceTypes, holderStructure, structureChoice)); } - structureElements.addAll(StructureElementUtil.getStructureElementsForDisciplines(disciplines, holderStructure, structureChoice)); - } else if (Type.DEVICEGROUP.equals(type)) { - List<DeviceGroup> deviceGroups = holderRepositories.deviceGroupRepository().readDeviceGroups(statuses, deleted, - uuid, parent, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, - includeHistory, orderBy, isAsc, offset, limit); - totalCount = holderRepositories.deviceGroupRepository().countDeviceGroups(statuses, deleted, - uuid, parent, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, - includeHistory); - structureElements.addAll(StructureElementUtil.getStructureElementsForDeviceGroups(deviceGroups, holderStructure, structureChoice)); - } else if (Type.DEVICETYPE.equals(type)) { - List<DeviceType> deviceTypes = holderRepositories.deviceTypeRepository().readDeviceTypes(statuses, deleted, - uuid, parent, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, - includeHistory, orderBy, isAsc, offset, limit); - totalCount = holderRepositories.deviceTypeRepository().countDeviceTypes(statuses, deleted, - uuid, parent, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, - includeHistory); - structureElements.addAll(StructureElementUtil.getStructureElementsForDeviceTypes(deviceTypes, holderStructure, structureChoice)); } ResponsePageStructureElements response = new ResponsePageStructureElements(structureElements, totalCount, structureElements.size(), offset, limit); @@ -336,15 +339,15 @@ public class StructuresService { } public ResponsePageStructureElements readStructuresChildren(String uuid, Type type, - Status[] statuses, Boolean deleted, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, + Status[] statuses, Boolean deleted, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, FieldStructure orderBy, Boolean isAsc, Integer offset, Integer limit) { // validation outside method // read structure latest by uuid for type // return structure elements for structures if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, "Read structures children", "uuid", uuid)); - LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, "Read structures children", "type", type)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES_CHILDREN, "uuid", uuid)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES_CHILDREN, "type", type)); } boolean typeSystemGroup = Type.SYSTEMGROUP.equals(type); @@ -359,13 +362,13 @@ public class StructuresService { ResponsePageStructureElements response = null; if (typeEither) { if (typeSystemGroup) { - response = readStructures(Type.SYSTEM, new Status[] {Status.APPROVED}, false, null, uuid, null, null, null, null, null, orderBy, isAsc, offset, limit); + response = readStructures(Type.SYSTEM, new Status[] {Status.APPROVED}, false, null, uuid, null, null, null, null, null, null, orderBy, isAsc, offset, limit); } else if (typeSystem) { - response = readStructures(Type.SUBSYSTEM, new Status[] {Status.APPROVED}, false, null, uuid, null, null, null, null, null, orderBy, isAsc, offset, limit); + response = readStructures(Type.SUBSYSTEM, new Status[] {Status.APPROVED}, false, null, uuid, null, null, null, null, null, null, orderBy, isAsc, offset, limit); } else if (typeDiscipline) { - response = readStructures(Type.DEVICEGROUP, new Status[] {Status.APPROVED}, false, null, uuid, null, null, null, null, null, orderBy, isAsc, offset, limit); + response = readStructures(Type.DEVICEGROUP, new Status[] {Status.APPROVED}, false, null, uuid, null, null, null, null, null, null, orderBy, isAsc, offset, limit); } else if (typeDeviceGroup) { - response = readStructures(Type.DEVICETYPE, new Status[] {Status.APPROVED}, false, null, uuid, null, null, null, null, null, orderBy, isAsc, offset, limit); + response = readStructures(Type.DEVICETYPE, new Status[] {Status.APPROVED}, false, null, uuid, null, null, null, null, null, null, orderBy, isAsc, offset, limit); } else { // no children in structures for subsystem and device type response = new ResponsePageStructureElements(structureElements, Long.valueOf(structureElements.size()), structureElements.size(), offset, limit); @@ -374,10 +377,10 @@ public class StructuresService { // go through all structures and see if / where uuid is found // uuid in 0 or 1 of structures - ResponsePageStructureElements responseSystemGroup = readStructures(Type.SYSTEM, new Status[] {Status.APPROVED}, false, null, uuid, null, null, null, null, null, orderBy, isAsc, offset, limit); - ResponsePageStructureElements responseSystem = readStructures(Type.SUBSYSTEM, new Status[] {Status.APPROVED}, false, null, uuid, null, null, null, null, null, orderBy, isAsc, offset, limit); - ResponsePageStructureElements responseDiscipline = readStructures(Type.DEVICEGROUP, new Status[] {Status.APPROVED}, false, null, uuid, null, null, null, null, null, orderBy, isAsc, offset, limit); - ResponsePageStructureElements responseDeviceGroup = readStructures(Type.DEVICETYPE, new Status[] {Status.APPROVED}, false, null, uuid, null, null, null, null, null, orderBy, isAsc, offset, limit); + ResponsePageStructureElements responseSystemGroup = readStructures(Type.SYSTEM, new Status[] {Status.APPROVED}, false, null, uuid, null, null, null, null, null, null, orderBy, isAsc, offset, limit); + ResponsePageStructureElements responseSystem = readStructures(Type.SUBSYSTEM, new Status[] {Status.APPROVED}, false, null, uuid, null, null, null, null, null, null, orderBy, isAsc, offset, limit); + ResponsePageStructureElements responseDiscipline = readStructures(Type.DEVICEGROUP, new Status[] {Status.APPROVED}, false, null, uuid, null, null, null, null, null, null, orderBy, isAsc, offset, limit); + ResponsePageStructureElements responseDeviceGroup = readStructures(Type.DEVICETYPE, new Status[] {Status.APPROVED}, false, null, uuid, null, null, null, null, null, null, orderBy, isAsc, offset, limit); structureElements.addAll(responseSystemGroup.getList()); structureElements.addAll(responseSystem.getList()); @@ -396,16 +399,16 @@ public class StructuresService { // read structure latest by mnemonic // return structure elements for structures - LOGGER.log(Level.FINE, () -> MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, "Read structures mnemonic", "mnemonic", mnemonic)); + LOGGER.log(Level.FINE, () -> MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES_MNEMONIC, "mnemonic", mnemonic)); // TODO handle orderBy, isAsc, offset, limit - ResponsePageStructureElements responseSystemGroup = readStructures(Type.SYSTEMGROUP, new Status[] {Status.APPROVED}, false, null, null, null, mnemonic, null, null, null, orderBy, isAsc, offset, limit); - ResponsePageStructureElements responseSystem = readStructures(Type.SYSTEM, new Status[] {Status.APPROVED}, false, null, null, null, mnemonic, null, null, null, orderBy, isAsc, offset, limit); - ResponsePageStructureElements responseSubsystem = readStructures(Type.SUBSYSTEM, new Status[] {Status.APPROVED}, false, null, null, null, mnemonic, null, null, null, orderBy, isAsc, offset, limit); - ResponsePageStructureElements responseDiscipline = readStructures(Type.DISCIPLINE, new Status[] {Status.APPROVED}, false, null, null, null, mnemonic, null, null, null, orderBy, isAsc, offset, limit); - ResponsePageStructureElements responseDeviceGroup = readStructures(Type.DEVICEGROUP, new Status[] {Status.APPROVED}, false, null, null, null, mnemonic, null, null, null, orderBy, isAsc, offset, limit); - ResponsePageStructureElements responseDeviceType = readStructures(Type.DEVICETYPE, new Status[] {Status.APPROVED}, false, null, null, null, mnemonic, null, null, null, orderBy, isAsc, offset, limit); + ResponsePageStructureElements responseSystemGroup = readStructures(Type.SYSTEMGROUP, new Status[] {Status.APPROVED}, false, null, null, null, mnemonic, null, null, null, null, orderBy, isAsc, offset, limit); + ResponsePageStructureElements responseSystem = readStructures(Type.SYSTEM, new Status[] {Status.APPROVED}, false, null, null, null, mnemonic, null, null, null, null, orderBy, isAsc, offset, limit); + ResponsePageStructureElements responseSubsystem = readStructures(Type.SUBSYSTEM, new Status[] {Status.APPROVED}, false, null, null, null, mnemonic, null, null, null, null, orderBy, isAsc, offset, limit); + ResponsePageStructureElements responseDiscipline = readStructures(Type.DISCIPLINE, new Status[] {Status.APPROVED}, false, null, null, null, mnemonic, null, null, null, null, orderBy, isAsc, offset, limit); + ResponsePageStructureElements responseDeviceGroup = readStructures(Type.DEVICEGROUP, new Status[] {Status.APPROVED}, false, null, null, null, mnemonic, null, null, null, null, orderBy, isAsc, offset, limit); + ResponsePageStructureElements responseDeviceType = readStructures(Type.DEVICETYPE, new Status[] {Status.APPROVED}, false, null, null, null, mnemonic, null, null, null, null, orderBy, isAsc, offset, limit); List<StructureElement> structureElements = Lists.newArrayList(); structureElements.addAll(responseSystemGroup.getList()); @@ -424,16 +427,16 @@ public class StructuresService { // read structure latest by mnemonic path // return structure elements for structures - LOGGER.log(Level.FINE, () -> MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, "Read structures mnemonic path", "mnemonicPath", mnemonicPath)); + LOGGER.log(Level.FINE, () -> MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES_MNEMONIC_PATH, "mnemonicPath", mnemonicPath)); // TODO handle orderBy, isAsc, offset, limit - ResponsePageStructureElements responseSystemGroup = readStructures(Type.SYSTEMGROUP, new Status[] {Status.APPROVED}, false, null, null, null, null, null, mnemonicPath, null, orderBy, isAsc, offset, limit); - ResponsePageStructureElements responseSystem = readStructures(Type.SYSTEM, new Status[] {Status.APPROVED}, false, null, null, null, null, null, mnemonicPath, null, orderBy, isAsc, offset, limit); - ResponsePageStructureElements responseSubsystem = readStructures(Type.SUBSYSTEM, new Status[] {Status.APPROVED}, false, null, null, null, null, null, mnemonicPath, null, orderBy, isAsc, offset, limit); - ResponsePageStructureElements responseDiscipline = readStructures(Type.DISCIPLINE, new Status[] {Status.APPROVED}, false, null, null, null, null, null, mnemonicPath, null, orderBy, isAsc, offset, limit); - ResponsePageStructureElements responseDeviceGroup = readStructures(Type.DEVICEGROUP, new Status[] {Status.APPROVED}, false, null, null, null, null, null, mnemonicPath, null, orderBy, isAsc, offset, limit); - ResponsePageStructureElements responseDeviceType = readStructures(Type.DEVICETYPE, new Status[] {Status.APPROVED}, false, null, null, null, null, null, mnemonicPath, null, orderBy, isAsc, offset, limit); + ResponsePageStructureElements responseSystemGroup = readStructures(Type.SYSTEMGROUP, new Status[] {Status.APPROVED}, false, null, null, null, null, null, mnemonicPath, null, null, orderBy, isAsc, offset, limit); + ResponsePageStructureElements responseSystem = readStructures(Type.SYSTEM, new Status[] {Status.APPROVED}, false, null, null, null, null, null, mnemonicPath, null, null, orderBy, isAsc, offset, limit); + ResponsePageStructureElements responseSubsystem = readStructures(Type.SUBSYSTEM, new Status[] {Status.APPROVED}, false, null, null, null, null, null, mnemonicPath, null, null, orderBy, isAsc, offset, limit); + ResponsePageStructureElements responseDiscipline = readStructures(Type.DISCIPLINE, new Status[] {Status.APPROVED}, false, null, null, null, null, null, mnemonicPath, null, null, orderBy, isAsc, offset, limit); + ResponsePageStructureElements responseDeviceGroup = readStructures(Type.DEVICEGROUP, new Status[] {Status.APPROVED}, false, null, null, null, null, null, mnemonicPath, null, null, orderBy, isAsc, offset, limit); + ResponsePageStructureElements responseDeviceType = readStructures(Type.DEVICETYPE, new Status[] {Status.APPROVED}, false, null, null, null, null, null, mnemonicPath, null, null, orderBy, isAsc, offset, limit); List<StructureElement> structureElements = Lists.newArrayList(); structureElements.addAll(responseSystemGroup.getList()); @@ -446,6 +449,82 @@ public class StructuresService { return new ResponsePageStructureElements(structureElements, Long.valueOf(structureElements.size()), structureElements.size(), 0, structureElements.size()); } + public ResponsePageStructureElements readStructuresHistory(Type type, + String uuid, String parent, String name, String mnemonic, String mnemonicEquivalence, String description, String who, + FieldStructure orderBy, Boolean isAsc, Integer offset, Integer limit) { + // validation outside method + // read history for structure + // return structure elements for structures + + if (LOGGER.isLoggable(Level.FINE)) { + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES_HISTORY, "uuid", uuid)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES_HISTORY, "parent", parent)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES_HISTORY, "name", name)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES_HISTORY, "mnemonic", mnemonic)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES_HISTORY, "mnemonicEquivalence", mnemonicEquivalence)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES_HISTORY, "description", description)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES_HISTORY, "who", who)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES_HISTORY, "orderBy", orderBy)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES_HISTORY, "isAsc", isAsc)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES_HISTORY, "offset", offset)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES_HISTORY, "limit", limit)); + } + + boolean typeSystemGroup = Type.SYSTEMGROUP.equals(type); + boolean typeSystem = Type.SYSTEM.equals(type); + boolean typeSubsystem = Type.SUBSYSTEM.equals(type); + boolean typeDiscipline = Type.DISCIPLINE.equals(type); + boolean typeDeviceGroup = Type.DEVICEGROUP.equals(type); + boolean typeDeviceType = Type.DEVICETYPE.equals(type); + boolean typeEither = ValidateUtil.isAnyTrue(typeSystemGroup, typeSystem, typeSubsystem, typeDiscipline, typeDeviceGroup, typeDeviceType); + + // mnemonic path does not make same sense for history + // very (!) tricky to find mnemonic path for uuid at proper time (history) + // therefore + // empty mnemonic path for history for structure + // not possible to search on mnemonic path for history + + final List<StructureElement> structureElements = Lists.newArrayList(); + ResponsePageStructureElements response = null; + if (typeEither) { + if (typeSystemGroup) { + response = readStructures(Type.SYSTEMGROUP, null, null, uuid, parent, name, mnemonic, mnemonicEquivalence, null, description, who, Boolean.TRUE, orderBy, isAsc, offset, limit, StructureChoice.HISTORY); + } else if (typeSystem) { + response = readStructures(Type.SYSTEM, null, null, uuid, parent, name, mnemonic, mnemonicEquivalence, null, description, who, Boolean.TRUE, orderBy, isAsc, offset, limit, StructureChoice.HISTORY); + } else if (typeSubsystem) { + response = readStructures(Type.SUBSYSTEM, null, null, uuid, parent, name, mnemonic, mnemonicEquivalence, null, description, who, Boolean.TRUE, orderBy, isAsc, offset, limit, StructureChoice.HISTORY); + } else if (typeDiscipline) { + response = readStructures(Type.DISCIPLINE, null, null, uuid, parent, name, mnemonic, mnemonicEquivalence, null, description, who, Boolean.TRUE, orderBy, isAsc, offset, limit, StructureChoice.HISTORY); + } else if (typeDeviceGroup) { + response = readStructures(Type.DEVICEGROUP, null, null, uuid, parent, name, mnemonic, mnemonicEquivalence, null, description, who, Boolean.TRUE, orderBy, isAsc, offset, limit, StructureChoice.HISTORY); + } else if (typeDeviceType) { + response = readStructures(Type.DEVICETYPE, null, null, uuid, parent, name, mnemonic, mnemonicEquivalence, null, description, who, Boolean.TRUE, orderBy, isAsc, offset, limit, StructureChoice.HISTORY); + } + } else { + // go through all structures and see if / where uuid is found + // uuid in 0 or 1 of structures + + ResponsePageStructureElements responseSystemGroup = readStructures(Type.SYSTEMGROUP, null, null, uuid, parent, name, mnemonic, mnemonicEquivalence, null, description, who, Boolean.TRUE, orderBy, isAsc, offset, limit, StructureChoice.HISTORY); + ResponsePageStructureElements responseSystem = readStructures(Type.SYSTEM, null, null, uuid, parent, name, mnemonic, mnemonicEquivalence, null, description, who, Boolean.TRUE, orderBy, isAsc, offset, limit, StructureChoice.HISTORY); + ResponsePageStructureElements responseSubsystem = readStructures(Type.SUBSYSTEM, null, null, uuid, parent, name, mnemonic, mnemonicEquivalence, null, description, who, Boolean.TRUE, orderBy, isAsc, offset, limit, StructureChoice.HISTORY); + ResponsePageStructureElements responseDiscipline = readStructures(Type.DISCIPLINE, null, null, uuid, parent, name, mnemonic, mnemonicEquivalence, null, description, who, Boolean.TRUE, orderBy, isAsc, offset, limit, StructureChoice.HISTORY); + ResponsePageStructureElements responseDeviceGroup = readStructures(Type.DEVICEGROUP, null, null, uuid, parent, name, mnemonic, mnemonicEquivalence, null, description, who, Boolean.TRUE, orderBy, isAsc, offset, limit, StructureChoice.HISTORY); + ResponsePageStructureElements responseDeviceType = readStructures(Type.DEVICETYPE, null, null, uuid, parent, name, mnemonic, mnemonicEquivalence, null, description, who, Boolean.TRUE, orderBy, isAsc, offset, limit, StructureChoice.HISTORY); + + structureElements.addAll(responseSystemGroup.getList()); + structureElements.addAll(responseSystem.getList()); + structureElements.addAll(responseSubsystem.getList()); + structureElements.addAll(responseDiscipline.getList()); + structureElements.addAll(responseDeviceGroup.getList()); + structureElements.addAll(responseDeviceType.getList()); + + // uuid is in max one structure + response = new ResponsePageStructureElements(structureElements, Long.valueOf(structureElements.size()), structureElements.size(), offset, limit); + } + + return response; + } + /** * Read history for structure by uuid. * @@ -462,8 +541,8 @@ public class StructuresService { // type may speed up read if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, "Read structures history", "uuid", uuid)); - LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, "Read structures history", "type", type)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES_HISTORY, "uuid", uuid)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.READ_STRUCTURES_HISTORY, "type", type)); } boolean typeSystemGroup = Type.SYSTEMGROUP.equals(type); @@ -475,35 +554,35 @@ public class StructuresService { boolean typeEither = ValidateUtil.isAnyTrue(typeSystemGroup, typeSystem, typeSubsystem, typeDiscipline, typeDeviceGroup, typeDeviceType); // mnemonic path does not make same sense for history - // (very) tricky to find mnemonic path for uuid at proper time (history) + // very (!) tricky to find mnemonic path for uuid at proper time (history) // therefore empty mnemonic path for history for structure final List<StructureElement> structureElements = Lists.newArrayList(); ResponsePageStructureElements response = null; if (typeEither) { if (typeSystemGroup) { - response = readStructures(Type.SYSTEMGROUP, null, null, uuid, null, null, null, null, null, null, Boolean.TRUE, orderBy, isAsc, offset, limit, StructureChoice.HISTORY); + response = readStructures(Type.SYSTEMGROUP, null, null, uuid, null, null, null, null, null, null, null, Boolean.TRUE, orderBy, isAsc, offset, limit, StructureChoice.HISTORY); } else if (typeSystem) { - response = readStructures(Type.SYSTEM, null, null, uuid, null, null, null, null, null, null, Boolean.TRUE, orderBy, isAsc, offset, limit, StructureChoice.HISTORY); + response = readStructures(Type.SYSTEM, null, null, uuid, null, null, null, null, null, null, null, Boolean.TRUE, orderBy, isAsc, offset, limit, StructureChoice.HISTORY); } else if (typeSubsystem) { - response = readStructures(Type.SUBSYSTEM, null, null, uuid, null, null, null, null, null, null, Boolean.TRUE, orderBy, isAsc, offset, limit, StructureChoice.HISTORY); + response = readStructures(Type.SUBSYSTEM, null, null, uuid, null, null, null, null, null, null, null, Boolean.TRUE, orderBy, isAsc, offset, limit, StructureChoice.HISTORY); } else if (typeDiscipline) { - response = readStructures(Type.DISCIPLINE, null, null, uuid, null, null, null, null, null, null, Boolean.TRUE, orderBy, isAsc, offset, limit, StructureChoice.HISTORY); + response = readStructures(Type.DISCIPLINE, null, null, uuid, null, null, null, null, null, null, null, Boolean.TRUE, orderBy, isAsc, offset, limit, StructureChoice.HISTORY); } else if (typeDeviceGroup) { - response = readStructures(Type.DEVICEGROUP, null, null, uuid, null, null, null, null, null, null, Boolean.TRUE, orderBy, isAsc, offset, limit, StructureChoice.HISTORY); + response = readStructures(Type.DEVICEGROUP, null, null, uuid, null, null, null, null, null, null, null, Boolean.TRUE, orderBy, isAsc, offset, limit, StructureChoice.HISTORY); } else if (typeDeviceType) { - response = readStructures(Type.DEVICETYPE, null, null, uuid, null, null, null, null, null, null, Boolean.TRUE, orderBy, isAsc, offset, limit, StructureChoice.HISTORY); + response = readStructures(Type.DEVICETYPE, null, null, uuid, null, null, null, null, null, null, null, Boolean.TRUE, orderBy, isAsc, offset, limit, StructureChoice.HISTORY); } } else { // go through all structures and see if / where uuid is found // uuid in 0 or 1 of structures - ResponsePageStructureElements responseSystemGroup = readStructures(Type.SYSTEMGROUP, null, null, uuid, null, null, null, null, null, null, Boolean.TRUE, orderBy, isAsc, offset, limit, StructureChoice.HISTORY); - ResponsePageStructureElements responseSystem = readStructures(Type.SYSTEM, null, null, uuid, null, null, null, null, null, null, Boolean.TRUE, orderBy, isAsc, offset, limit, StructureChoice.HISTORY); - ResponsePageStructureElements responseSubsystem = readStructures(Type.SUBSYSTEM, null, null, uuid, null, null, null, null, null, null, Boolean.TRUE, orderBy, isAsc, offset, limit, StructureChoice.HISTORY); - ResponsePageStructureElements responseDiscipline = readStructures(Type.DISCIPLINE, null, null, uuid, null, null, null, null, null, null, Boolean.TRUE, orderBy, isAsc, offset, limit, StructureChoice.HISTORY); - ResponsePageStructureElements responseDeviceGroup = readStructures(Type.DEVICEGROUP, null, null, uuid, null, null, null, null, null, null, Boolean.TRUE, orderBy, isAsc, offset, limit, StructureChoice.HISTORY); - ResponsePageStructureElements responseDeviceType = readStructures(Type.DEVICETYPE, null, null, uuid, null, null, null, null, null, null, Boolean.TRUE, orderBy, isAsc, offset, limit, StructureChoice.HISTORY); + ResponsePageStructureElements responseSystemGroup = readStructures(Type.SYSTEMGROUP, null, null, uuid, null, null, null, null, null, null, null, Boolean.TRUE, orderBy, isAsc, offset, limit, StructureChoice.HISTORY); + ResponsePageStructureElements responseSystem = readStructures(Type.SYSTEM, null, null, uuid, null, null, null, null, null, null, null, Boolean.TRUE, orderBy, isAsc, offset, limit, StructureChoice.HISTORY); + ResponsePageStructureElements responseSubsystem = readStructures(Type.SUBSYSTEM, null, null, uuid, null, null, null, null, null, null, null, Boolean.TRUE, orderBy, isAsc, offset, limit, StructureChoice.HISTORY); + ResponsePageStructureElements responseDiscipline = readStructures(Type.DISCIPLINE, null, null, uuid, null, null, null, null, null, null, null, Boolean.TRUE, orderBy, isAsc, offset, limit, StructureChoice.HISTORY); + ResponsePageStructureElements responseDeviceGroup = readStructures(Type.DEVICEGROUP, null, null, uuid, null, null, null, null, null, null, null, Boolean.TRUE, orderBy, isAsc, offset, limit, StructureChoice.HISTORY); + ResponsePageStructureElements responseDeviceType = readStructures(Type.DEVICETYPE, null, null, uuid, null, null, null, null, null, null, null, Boolean.TRUE, orderBy, isAsc, offset, limit, StructureChoice.HISTORY); structureElements.addAll(responseSystemGroup.getList()); structureElements.addAll(responseSystem.getList()); @@ -525,7 +604,7 @@ public class StructuresService { // validation outside method // read equivalence - LOGGER.log(Level.FINE, () -> MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, "Equivalence mnemonic", "mnemonic", mnemonic)); + LOGGER.log(Level.FINE, () -> MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.EQUIVALENCE_MNEMONIC, "mnemonic", mnemonic)); return namingConvention.equivalenceClassRepresentative(mnemonic); } @@ -535,26 +614,26 @@ public class StructuresService { // read exists if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, "Exists structure", "type", type)); - LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, "Exists structure", "mnemonicPath", mnemonicPath)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.EXISTS_STRUCTURE, "type", type)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.EXISTS_STRUCTURE, "mnemonicPath", mnemonicPath)); } if (Type.SYSTEMGROUP.equals(type)) { - List<SystemGroup> systemGroups = holderRepositories.systemGroupRepository().readSystemGroups(Status.APPROVED, false, null, null, null, null, mnemonicPath, null); + List<SystemGroup> systemGroups = holderRepositories.systemGroupRepository().readSystemGroups(Status.APPROVED, false, null, null, null, null, mnemonicPath, null, null); return !systemGroups.isEmpty(); } else if (Type.SYSTEM.equals(type)) { - List<System> systems = holderRepositories.systemRepository().readSystems(Status.APPROVED, false, null, null, null, null, null, mnemonicPath, null); + List<System> systems = holderRepositories.systemRepository().readSystems(Status.APPROVED, false, null, null, null, null, null, mnemonicPath, null, null); return !systems.isEmpty(); } else if (Type.SUBSYSTEM.equals(type)) { - List<Subsystem> subsystems = holderRepositories.subsystemRepository().readSubsystems(Status.APPROVED, false, null, null, null, null, null, mnemonicPath, null); + List<Subsystem> subsystems = holderRepositories.subsystemRepository().readSubsystems(Status.APPROVED, false, null, null, null, null, null, mnemonicPath, null, null); return !subsystems.isEmpty(); } else if (Type.DISCIPLINE.equals(type)) { - List<Discipline> disciplines = holderRepositories.disciplineRepository().readDisciplines(Status.APPROVED, false, null, null, null, null, mnemonicPath, null); + List<Discipline> disciplines = holderRepositories.disciplineRepository().readDisciplines(Status.APPROVED, false, null, null, null, null, mnemonicPath, null, null); return !disciplines.isEmpty(); } else if (Type.DEVICEGROUP.equals(type)) { return Boolean.FALSE; } else if (Type.DEVICETYPE.equals(type)) { - List<DeviceType> deviceTypes = holderRepositories.deviceTypeRepository().readDeviceTypes(Status.APPROVED, false, null, null, null, null, null, mnemonicPath, null); + List<DeviceType> deviceTypes = holderRepositories.deviceTypeRepository().readDeviceTypes(Status.APPROVED, false, null, null, null, null, null, mnemonicPath, null, null); return !deviceTypes.isEmpty(); } @@ -566,8 +645,8 @@ public class StructuresService { // validate data - not exists if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, "Is valid to create structure", "type", type)); - LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, "Is valid to create structure", "mnemonicPath", mnemonicPath)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.IS_VALID_TO_CREATE_STRUCTURE, "type", type)); + LOGGER.log(Level.FINE, MessageFormat.format(TextUtil.DESCRIPTION_NAME_VALUE, TextUtil.IS_VALID_TO_CREATE_STRUCTURE, "mnemonicPath", mnemonicPath)); } // initiate holder of system and device structure content, for performance reasons diff --git a/src/main/java/org/openepics/names/service/SubsystemService.java b/src/main/java/org/openepics/names/service/SubsystemService.java index 8d9d5484e2512fe4327aba687eeead583dbd21a2..dfef5ee69f6daa1231aa5b21bbbc0621ecc093c0 100644 --- a/src/main/java/org/openepics/names/service/SubsystemService.java +++ b/src/main/java/org/openepics/names/service/SubsystemService.java @@ -165,7 +165,7 @@ public class SubsystemService { // uuid, comment // find - List<Subsystem> subsystems = subsystemRepository.readSubsystems(Status.APPROVED, Boolean.FALSE, structureElementCommand.getUuid().toString(), null, null, null, null, null, null); + List<Subsystem> subsystems = subsystemRepository.readSubsystems(Status.APPROVED, Boolean.FALSE, structureElementCommand.getUuid().toString(), null, null, null, null, null, null, null); if (ValidateUtil.isNullOrNotSize(subsystems, 1)) { return null; } @@ -218,7 +218,7 @@ public class SubsystemService { String uuid = structureElementCommand.getUuid().toString(); // find - List<Subsystem> subsystems = subsystemRepository.readSubsystems(Status.APPROVED, Boolean.FALSE, uuid, null, null, null, null, null, null); + List<Subsystem> subsystems = subsystemRepository.readSubsystems(Status.APPROVED, Boolean.FALSE, uuid, null, null, null, null, null, null, null); Subsystem subsystem = null; if (ValidateUtil.isSize(subsystems, 1)) { subsystem = subsystems.get(0); @@ -229,7 +229,7 @@ public class SubsystemService { } // find - subsystems = subsystemRepository.readSubsystems(Status.PENDING, null, uuid, null, null, null, null, null, null); + subsystems = subsystemRepository.readSubsystems(Status.PENDING, null, uuid, null, null, null, null, null, null, null); if (ValidateUtil.isNullOrNotSize(subsystems, 1)) { return null; } @@ -285,7 +285,7 @@ public class SubsystemService { String uuid = structureElementCommand.getUuid().toString(); // find - List<Subsystem> subsystems = subsystemRepository.readSubsystems(Status.PENDING, null, uuid, null, null, null, null, null, null); + List<Subsystem> subsystems = subsystemRepository.readSubsystems(Status.PENDING, null, uuid, null, null, null, null, null, null, null); if (ValidateUtil.isNullOrNotSize(subsystems, 1)) { return null; } @@ -326,7 +326,7 @@ public class SubsystemService { String uuid = structureElementCommand.getUuid().toString(); // find - List<Subsystem> subsystems = subsystemRepository.readSubsystems(Status.PENDING, null, uuid, null, null, null, null, null, null); + List<Subsystem> subsystems = subsystemRepository.readSubsystems(Status.PENDING, null, uuid, null, null, null, null, null, null, null); if (ValidateUtil.isNullOrNotSize(subsystems, 1)) { return null; } diff --git a/src/main/java/org/openepics/names/service/SystemGroupService.java b/src/main/java/org/openepics/names/service/SystemGroupService.java index 3c875ededa29298dc94a39f14a67642dc2bb8223..046c6720d1fd5ca285c41c29e5fb002f5f935fdc 100644 --- a/src/main/java/org/openepics/names/service/SystemGroupService.java +++ b/src/main/java/org/openepics/names/service/SystemGroupService.java @@ -175,7 +175,7 @@ public class SystemGroupService { // uuid, comment // find - List<SystemGroup> systemGroups = systemGroupRepository.readSystemGroups(Status.APPROVED, Boolean.FALSE, structureElementCommand.getUuid().toString(), null, null, null, null, null); + List<SystemGroup> systemGroups = systemGroupRepository.readSystemGroups(Status.APPROVED, Boolean.FALSE, structureElementCommand.getUuid().toString(), null, null, null, null, null, null); if (ValidateUtil.isNullOrNotSize(systemGroups, 1)) { return null; } @@ -228,7 +228,7 @@ public class SystemGroupService { String uuid = structureElementCommand.getUuid().toString(); // find - List<SystemGroup> systemGroups = systemGroupRepository.readSystemGroups(Status.APPROVED, Boolean.FALSE, uuid, null, null, null, null, null); + List<SystemGroup> systemGroups = systemGroupRepository.readSystemGroups(Status.APPROVED, Boolean.FALSE, uuid, null, null, null, null, null, null); SystemGroup systemGroup = null; if (ValidateUtil.isSize(systemGroups, 1)) { systemGroup = systemGroups.get(0); @@ -239,7 +239,7 @@ public class SystemGroupService { } // find - systemGroups = systemGroupRepository.readSystemGroups(Status.PENDING, null, uuid, null, null, null, null, null); + systemGroups = systemGroupRepository.readSystemGroups(Status.PENDING, null, uuid, null, null, null, null, null, null); if (ValidateUtil.isNullOrNotSize(systemGroups, 1)) { return null; } @@ -307,7 +307,7 @@ public class SystemGroupService { String uuid = structureElementCommand.getUuid().toString(); // find - List<SystemGroup> systemGroups = systemGroupRepository.readSystemGroups(Status.PENDING, null, uuid, null, null, null, null, null); + List<SystemGroup> systemGroups = systemGroupRepository.readSystemGroups(Status.PENDING, null, uuid, null, null, null, null, null, null); if (ValidateUtil.isNullOrNotSize(systemGroups, 1)) { return null; } @@ -348,7 +348,7 @@ public class SystemGroupService { String uuid = structureElementCommand.getUuid().toString(); // find - List<SystemGroup> systemGroups = systemGroupRepository.readSystemGroups(Status.PENDING, null, uuid, null, null, null, null, null); + List<SystemGroup> systemGroups = systemGroupRepository.readSystemGroups(Status.PENDING, null, uuid, null, null, null, null, null, null); if (ValidateUtil.isNullOrNotSize(systemGroups, 1)) { return null; } diff --git a/src/main/java/org/openepics/names/service/SystemService.java b/src/main/java/org/openepics/names/service/SystemService.java index ede7a6dd6f00d0c369f3aa193ad5109fcab1cee1..6f5e06d4344d89bd996d56634cd78055022fb9f9 100644 --- a/src/main/java/org/openepics/names/service/SystemService.java +++ b/src/main/java/org/openepics/names/service/SystemService.java @@ -175,7 +175,7 @@ public class SystemService { // uuid, comment // find - List<System> systems = systemRepository.readSystems(Status.APPROVED, Boolean.FALSE, structureElementCommand.getUuid().toString(), null, null, null, null, null, null); + List<System> systems = systemRepository.readSystems(Status.APPROVED, Boolean.FALSE, structureElementCommand.getUuid().toString(), null, null, null, null, null, null, null); if (ValidateUtil.isNullOrNotSize(systems, 1)) { return null; } @@ -228,7 +228,7 @@ public class SystemService { String uuid = structureElementCommand.getUuid().toString(); // find - List<System> systems = systemRepository.readSystems(Status.APPROVED, Boolean.FALSE, uuid, null, null, null, null, null, null); + List<System> systems = systemRepository.readSystems(Status.APPROVED, Boolean.FALSE, uuid, null, null, null, null, null, null, null); System system = null; if (ValidateUtil.isSize(systems, 1)) { system = systems.get(0); @@ -239,7 +239,7 @@ public class SystemService { } // find - systems = systemRepository.readSystems(Status.PENDING, null, uuid, null, null, null, null, null, null); + systems = systemRepository.readSystems(Status.PENDING, null, uuid, null, null, null, null, null, null, null); if (ValidateUtil.isNullOrNotSize(systems, 1)) { return null; } @@ -307,7 +307,7 @@ public class SystemService { String uuid = structureElementCommand.getUuid().toString(); // find - List<System> systems = systemRepository.readSystems(Status.PENDING, null, uuid, null, null, null, null, null, null); + List<System> systems = systemRepository.readSystems(Status.PENDING, null, uuid, null, null, null, null, null, null, null); if (ValidateUtil.isNullOrNotSize(systems, 1)) { return null; } @@ -348,7 +348,7 @@ public class SystemService { String uuid = structureElementCommand.getUuid().toString(); // find - List<System> systems = systemRepository.readSystems(Status.PENDING, null, uuid, null, null, null, null, null, null); + List<System> systems = systemRepository.readSystems(Status.PENDING, null, uuid, null, null, null, null, null, null, null); if (ValidateUtil.isNullOrNotSize(systems, 1)) { return null; } diff --git a/src/main/java/org/openepics/names/util/TextUtil.java b/src/main/java/org/openepics/names/util/TextUtil.java index 0280213333a61922d5afa7db84a506f276212f4a..10680cdd364aa767df654466c0f27df25b4ec8b0 100644 --- a/src/main/java/org/openepics/names/util/TextUtil.java +++ b/src/main/java/org/openepics/names/util/TextUtil.java @@ -150,10 +150,17 @@ public class TextUtil { public static final String CREATE_STRUCTURE = "Create structure"; public static final String UPDATE_STRUCTURE = "Update structure"; public static final String DELETE_STRUCTURE = "Delete structure"; + public static final String READ_STRUCTURES = "Read structures"; + public static final String READ_STRUCTURES_HISTORY = "Read structures history"; + public static final String READ_STRUCTURES_CHILDREN = "Read structures children"; + public static final String READ_STRUCTURES_MNEMONIC = "Read structures mnemonic"; + public static final String READ_STRUCTURES_MNEMONIC_PATH = "Read structures mnemonic path"; + public static final String EQUIVALENCE_MNEMONIC = "Equivalence mnemonic"; + public static final String EXISTS_STRUCTURE = "Exists structure"; + public static final String IS_VALID_TO_CREATE_STRUCTURE = "Is valid to create structure"; public static final String APPROVE_STRUCTURE = "Approve structure"; public static final String CANCEL_STRUCTURE = "Cancel structure"; public static final String REJECT_STRUCTURE = "Reject structure"; - public static final String READ_STRUCTURES = "Read structures"; /** * This class is not to be instantiated. diff --git a/src/main/java/org/openepics/names/util/ValidateNameElementUtil.java b/src/main/java/org/openepics/names/util/ValidateNameElementUtil.java index fb6da8304d5a88470aa71941d0e56c78d084aab0..0135ab51515419d87b1616f145ba86415655569a 100644 --- a/src/main/java/org/openepics/names/util/ValidateNameElementUtil.java +++ b/src/main/java/org/openepics/names/util/ValidateNameElementUtil.java @@ -431,16 +431,16 @@ public class ValidateNameElementUtil { // device structure if (!StringUtils.isEmpty(dt)) { - List<DeviceType> deviceTypes = holderRepositories.deviceTypeRepository().readDeviceTypes(Status.APPROVED, false, null, null, null, null, null, mnemonicPathDeviceStructure, null); + List<DeviceType> deviceTypes = holderRepositories.deviceTypeRepository().readDeviceTypes(Status.APPROVED, false, null, null, null, null, null, mnemonicPathDeviceStructure, null, null); ExceptionUtil.validateConditionDataNotFoundException(ValidateUtil.isSize(deviceTypes, 1), TextUtil.DEVICE_STRUCTURE_IS_NOT_FOUND, details, field); deviceType = deviceTypes.get(0); } // system structure - List<Subsystem> subsystems = holderRepositories.subsystemRepository().readSubsystems(Status.APPROVED, false, null, null, null, null, null, mnemonicPathSystemStructure, null); - List<System> systems = holderRepositories.systemRepository().readSystems(Status.APPROVED, false, null, null, null, null, null, mnemonicPathSystemStructure, null); - List<SystemGroup> systemGroups = holderRepositories.systemGroupRepository().readSystemGroups(Status.APPROVED, false, null, null, null, null, mnemonicPathSystemStructure, null); + List<Subsystem> subsystems = holderRepositories.subsystemRepository().readSubsystems(Status.APPROVED, false, null, null, null, null, null, mnemonicPathSystemStructure, null, null); + List<System> systems = holderRepositories.systemRepository().readSystems(Status.APPROVED, false, null, null, null, null, null, mnemonicPathSystemStructure, null, null); + List<SystemGroup> systemGroups = holderRepositories.systemGroupRepository().readSystemGroups(Status.APPROVED, false, null, null, null, null, mnemonicPathSystemStructure, null, null); if (ValidateUtil.isSize(subsystems, 1)) { subsystem = subsystems.get(0); diff --git a/src/main/java/org/openepics/names/util/ValidateStructureElementUtil.java b/src/main/java/org/openepics/names/util/ValidateStructureElementUtil.java index 790793c750847d297470360db0d8ac83a0447949..69045d6d6c5aa79c607ef65a3cfc0e9a25fbb1b6 100644 --- a/src/main/java/org/openepics/names/util/ValidateStructureElementUtil.java +++ b/src/main/java/org/openepics/names/util/ValidateStructureElementUtil.java @@ -67,6 +67,41 @@ public class ValidateStructureElementUtil { throw new IllegalStateException("Utility class"); } + /** + * Validate parameters for read structures. + * + * @param statuses statuses + * @param deleted deleted + * @param uuid uuid + * @param parent parent uuid + * @param name name + * @param mnemonic mnemonic + * @param mnemonicEquivalence mnemonic equivalence + * @param mnemonicPath mnemonic path + * @param description description + * @param who, who + * @param includeHistory include history + * @param orderBy order by + * @param isAsc is ascending + * @param offset offset + * @param limit limit + */ + public static void validateStructuresInputRead(Status[] statuses, Boolean deleted, + String uuid, String parent, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, + Boolean includeHistory, FieldStructure orderBy, Boolean isAsc, Integer offset, Integer limit) { + + // validate input + // uuid + // parent + + if (!StringUtils.isEmpty(uuid)) { + ValidateUtil.validateInputUuid(uuid); + } + if (!StringUtils.isEmpty(parent)) { + ValidateUtil.validateInputUuid(parent); + } + } + /** * Validate parameters for read structures. * @@ -80,6 +115,7 @@ public class ValidateStructureElementUtil { * @param mnemonicEquivalence mnemonic equivalence * @param mnemonicPath mnemonic path * @param description description + * @param who, who * @param includeHistory include history * @param orderBy order by * @param isAsc is ascending @@ -87,17 +123,18 @@ public class ValidateStructureElementUtil { * @param limit limit */ public static void validateStructuresInputRead(Type type, Status[] statuses, Boolean deleted, - String uuid, String parent, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, + String uuid, String parent, String name, String mnemonic, String mnemonicEquivalence, String mnemonicPath, String description, String who, Boolean includeHistory, FieldStructure orderBy, Boolean isAsc, Integer offset, Integer limit) { // validate input // type // uuid + // parent ValidateUtil.validateInputType(type); - if (!StringUtils.isEmpty(uuid)) { - ValidateUtil.validateInputUuid(uuid); - } + validateStructuresInputRead(statuses, deleted, + uuid, parent, name, mnemonic, mnemonicEquivalence, mnemonicPath, description, who, + includeHistory, orderBy, isAsc, offset, limit); } /** @@ -378,17 +415,17 @@ public class ValidateStructureElementUtil { private static int getStructuresSize(UUID uuid, Type type, Status status, Boolean deleted, HolderRepositories holderRepositories) { if (Type.SYSTEMGROUP.equals(type)) { - return holderRepositories.systemGroupRepository().readSystemGroups(status, deleted, uuid.toString(), null, null, null, null, null).size(); + return holderRepositories.systemGroupRepository().readSystemGroups(status, deleted, uuid.toString(), null, null, null, null, null, null).size(); } else if (Type.SYSTEM.equals(type)) { - return holderRepositories.systemRepository().readSystems(status, deleted, uuid.toString(), null, null, null, null, null, null).size(); + return holderRepositories.systemRepository().readSystems(status, deleted, uuid.toString(), null, null, null, null, null, null, null).size(); } else if (Type.SUBSYSTEM.equals(type)) { - return holderRepositories.subsystemRepository().readSubsystems(status, deleted, uuid.toString(), null, null, null, null, null, null).size(); + return holderRepositories.subsystemRepository().readSubsystems(status, deleted, uuid.toString(), null, null, null, null, null, null, null).size(); } else if (Type.DISCIPLINE.equals(type)) { - return holderRepositories.disciplineRepository().readDisciplines(status, deleted, uuid.toString(), null, null, null, null, null).size(); + return holderRepositories.disciplineRepository().readDisciplines(status, deleted, uuid.toString(), null, null, null, null, null, null).size(); } else if (Type.DEVICEGROUP.equals(type)) { - return holderRepositories.deviceGroupRepository().readDeviceGroups(status, deleted, uuid.toString(), null, null, null, null, null, null).size(); + return holderRepositories.deviceGroupRepository().readDeviceGroups(status, deleted, uuid.toString(), null, null, null, null, null, null, null).size(); } else if (Type.DEVICETYPE.equals(type)) { - return holderRepositories.deviceTypeRepository().readDeviceTypes(status, deleted, uuid.toString(), null, null, null, null, null, null).size(); + return holderRepositories.deviceTypeRepository().readDeviceTypes(status, deleted, uuid.toString(), null, null, null, null, null, null, null).size(); } return 0; } @@ -502,7 +539,7 @@ public class ValidateStructureElementUtil { } else if (Type.DEVICEGROUP.equals(type)) { // status, parent message = TextUtil.DISCIPLINE_IS_NOT_CORRECT; - List<Discipline> disciplines = holderRepositories.disciplineRepository().readDisciplines(Status.APPROVED, false, parent.toString(), null, null, null, null, null); + List<Discipline> disciplines = holderRepositories.disciplineRepository().readDisciplines(Status.APPROVED, false, parent.toString(), null, null, null, null, null, null); ExceptionUtil.validateConditionDataNotFoundException(ValidateUtil.isSize(disciplines, 1), message, details, TextUtil.PARENT); @@ -545,7 +582,7 @@ public class ValidateStructureElementUtil { validateStructuresValidSize1(uuid, type, Status.PENDING, null, holderRepositories, message, details, field); - List<System> systems = holderRepositories.systemRepository().readSystems(Status.PENDING, null, uuid.toString(), null, null, null, null, null, null); + List<System> systems = holderRepositories.systemRepository().readSystems(Status.PENDING, null, uuid.toString(), null, null, null, null, null, null, null); // status, parent message = TextUtil.SYSTEMGROUP_IS_NOT_CORRECT; @@ -561,7 +598,7 @@ public class ValidateStructureElementUtil { validateStructuresValidSize1(uuid, type, Status.PENDING, null, holderRepositories, message, details, field); - List<Subsystem> subsystems = holderRepositories.subsystemRepository().readSubsystems(Status.PENDING, null, uuid.toString(), null, null, null, null, null, null); + List<Subsystem> subsystems = holderRepositories.subsystemRepository().readSubsystems(Status.PENDING, null, uuid.toString(), null, null, null, null, null, null, null); // status, parent message = TextUtil.SYSTEM_IS_NOT_CORRECT; @@ -584,7 +621,7 @@ public class ValidateStructureElementUtil { validateStructuresValidSize1(uuid, type, Status.PENDING, null, holderRepositories, message, details, field); - List<DeviceGroup> deviceGroups = holderRepositories.deviceGroupRepository().readDeviceGroups(Status.PENDING, null, uuid.toString(), null, null, null, null, null, null); + List<DeviceGroup> deviceGroups = holderRepositories.deviceGroupRepository().readDeviceGroups(Status.PENDING, null, uuid.toString(), null, null, null, null, null, null, null); // status, parent message = TextUtil.DISCIPLINE_IS_NOT_CORRECT; @@ -600,7 +637,7 @@ public class ValidateStructureElementUtil { validateStructuresValidSize1(uuid, type, Status.PENDING, null, holderRepositories, message, details, field); - List<DeviceType> deviceTypes = holderRepositories.deviceTypeRepository().readDeviceTypes(Status.PENDING, null, uuid.toString(), null, null, null, null, null, null); + List<DeviceType> deviceTypes = holderRepositories.deviceTypeRepository().readDeviceTypes(Status.PENDING, null, uuid.toString(), null, null, null, null, null, null, null); // status, parent message = TextUtil.DISCIPLINE_IS_NOT_CORRECT; @@ -655,13 +692,13 @@ public class ValidateStructureElementUtil { HolderRepositories holderRepositories) { String queryValue = parent.toString(); if (Type.SYSTEM.equals(type)) { - return holderRepositories.systemGroupRepository().readSystemGroups(status, deleted, queryValue, null, null, null, null, null).size(); + return holderRepositories.systemGroupRepository().readSystemGroups(status, deleted, queryValue, null, null, null, null, null, null).size(); } else if (Type.SUBSYSTEM.equals(type)) { - return holderRepositories.systemRepository().readSystems(status, deleted, queryValue, null, null, null, null, null, null).size(); + return holderRepositories.systemRepository().readSystems(status, deleted, queryValue, null, null, null, null, null, null, null).size(); } else if (Type.DEVICEGROUP.equals(type)) { - return holderRepositories.disciplineRepository().readDisciplines(status, deleted, queryValue, null, null, null, null, null).size(); + return holderRepositories.disciplineRepository().readDisciplines(status, deleted, queryValue, null, null, null, null, null, null).size(); } else if (Type.DEVICETYPE.equals(type)) { - return holderRepositories.deviceGroupRepository().readDeviceGroups(status, deleted, queryValue, null, null, null, null, null, null).size(); + return holderRepositories.deviceGroupRepository().readDeviceGroups(status, deleted, queryValue, null, null, null, null, null, null, null).size(); } return 0; } @@ -711,31 +748,31 @@ public class ValidateStructureElementUtil { // query table and return list with uuid if (Type.SYSTEMGROUP.equals(type)) { return StructureUtil.listSystemGroup2Uuid( - holderRepositories.systemGroupRepository().readSystemGroups(status, deleted, queryUuid, null, queryMnemonic, queryMnemonicEquivalence, null, null)); + holderRepositories.systemGroupRepository().readSystemGroups(status, deleted, queryUuid, null, queryMnemonic, queryMnemonicEquivalence, null, null, null)); } else if (Type.SYSTEM.equals(type)) { if (queryParentTable) { - return StructureUtil.listSystemGroup2Uuid(holderRepositories.systemGroupRepository().readSystemGroups(status, deleted, queryUuid, null, queryMnemonic, queryMnemonicEquivalence, null, null)); + return StructureUtil.listSystemGroup2Uuid(holderRepositories.systemGroupRepository().readSystemGroups(status, deleted, queryUuid, null, queryMnemonic, queryMnemonicEquivalence, null, null, null)); } else { - return StructureUtil.listSystem2Uuid(holderRepositories.systemRepository().readSystems(status, deleted, queryUuid, queryParent, null, queryMnemonic, queryMnemonicEquivalence, null, null)); + return StructureUtil.listSystem2Uuid(holderRepositories.systemRepository().readSystems(status, deleted, queryUuid, queryParent, null, queryMnemonic, queryMnemonicEquivalence, null, null, null)); } } else if (Type.SUBSYSTEM.equals(type)) { if (queryParentTable) { - return StructureUtil.listSystem2Uuid(holderRepositories.systemRepository().readSystems(status, deleted, queryUuid, queryParent, null, queryMnemonic, queryMnemonicEquivalence, null, null)); + return StructureUtil.listSystem2Uuid(holderRepositories.systemRepository().readSystems(status, deleted, queryUuid, queryParent, null, queryMnemonic, queryMnemonicEquivalence, null, null, null)); } else { - return StructureUtil.listSubsystem2Uuid(holderRepositories.subsystemRepository().readSubsystems(status, deleted, queryUuid, queryParent, null, queryMnemonic, queryMnemonicEquivalence, null, null)); + return StructureUtil.listSubsystem2Uuid(holderRepositories.subsystemRepository().readSubsystems(status, deleted, queryUuid, queryParent, null, queryMnemonic, queryMnemonicEquivalence, null, null, null)); } } else if (Type.DISCIPLINE.equals(type)) { - return StructureUtil.listDiscipline2Uuid(holderRepositories.disciplineRepository().readDisciplines(status, deleted, queryUuid, null, queryMnemonic, queryMnemonicEquivalence, null, null)); + return StructureUtil.listDiscipline2Uuid(holderRepositories.disciplineRepository().readDisciplines(status, deleted, queryUuid, null, queryMnemonic, queryMnemonicEquivalence, null, null, null)); } else if (Type.DEVICEGROUP.equals(type)) { if (queryParentTable) { - return StructureUtil.listDiscipline2Uuid(holderRepositories.disciplineRepository().readDisciplines(status, deleted, queryUuid, null, queryMnemonic, queryMnemonicEquivalence, null, null)); + return StructureUtil.listDiscipline2Uuid(holderRepositories.disciplineRepository().readDisciplines(status, deleted, queryUuid, null, queryMnemonic, queryMnemonicEquivalence, null, null, null)); } else { - return StructureUtil.listDeviceGroup2Uuid(holderRepositories.deviceGroupRepository().readDeviceGroups(status, deleted, queryUuid, queryParent, null, queryMnemonic, queryMnemonicEquivalence, null, null)); } + return StructureUtil.listDeviceGroup2Uuid(holderRepositories.deviceGroupRepository().readDeviceGroups(status, deleted, queryUuid, queryParent, null, queryMnemonic, queryMnemonicEquivalence, null, null, null)); } } else if (Type.DEVICETYPE.equals(type)) { if (queryParentTable) { - return StructureUtil.listDeviceGroup2Uuid(holderRepositories.deviceGroupRepository().readDeviceGroups(status, deleted, queryUuid, queryParent, null, queryMnemonic, queryMnemonicEquivalence, null, null)); + return StructureUtil.listDeviceGroup2Uuid(holderRepositories.deviceGroupRepository().readDeviceGroups(status, deleted, queryUuid, queryParent, null, queryMnemonic, queryMnemonicEquivalence, null, null, null)); } else { - return StructureUtil.listDeviceType2Uuid(holderRepositories.deviceTypeRepository().readDeviceTypes(status, deleted, queryUuid, queryParent, null, queryMnemonic, queryMnemonicEquivalence, null, null)); + return StructureUtil.listDeviceType2Uuid(holderRepositories.deviceTypeRepository().readDeviceTypes(status, deleted, queryUuid, queryParent, null, queryMnemonic, queryMnemonicEquivalence, null, null, null)); } } return Lists.newArrayList(); diff --git a/src/main/resources/static/pdfs/naming_rest_api_brief_introduction.pdf b/src/main/resources/static/pdfs/naming_rest_api_brief_introduction.pdf index a57e2cddc350ad52c2edff95c7e9fca4b8b6d80a..b5fc2de398e6d075a66c72c896e98020a1a43937 100644 Binary files a/src/main/resources/static/pdfs/naming_rest_api_brief_introduction.pdf and b/src/main/resources/static/pdfs/naming_rest_api_brief_introduction.pdf differ diff --git a/src/main/resources/static/pdfs/naming_rest_api_migration.pdf b/src/main/resources/static/pdfs/naming_rest_api_migration.pdf index a03af63e32af5099877147527b8461d414db1b1a..473394585bbff15399d464bcfe64ffc96ed2e402 100644 Binary files a/src/main/resources/static/pdfs/naming_rest_api_migration.pdf and b/src/main/resources/static/pdfs/naming_rest_api_migration.pdf differ diff --git a/src/test/java/org/openepics/names/docker/StructuresDeviceGroupIT.java b/src/test/java/org/openepics/names/docker/StructuresDeviceGroupIT.java index a2b9489bf489a6cfd50365b1a969710fea8d56eb..633810812f04ef91cfe289b50ace152daa4b2c35 100644 --- a/src/test/java/org/openepics/names/docker/StructuresDeviceGroupIT.java +++ b/src/test/java/org/openepics/names/docker/StructuresDeviceGroupIT.java @@ -1613,6 +1613,7 @@ class StructuresDeviceGroupIT { StructureElementCommandConfirm structureElementCommandConfirm = null; StructureElement createdStructureElement = null; UUID uuid = null; + UUID uuid2 = null; structureElementCommandCreate = new StructureElementCommandCreate( Type.DEVICEGROUP, discipline2Uuid, @@ -1730,6 +1731,7 @@ class StructuresDeviceGroupIT { "name", null, "description", "comment"); createdStructureElement = ITUtilStructureElement.assertCreateApprove(structureElementCommandCreate); + uuid2 = createdStructureElement.getUuid(); structureElementCommandUpdate = StructureElementUtil.convertElement2CommandUpdate(createdStructureElement); structureElementCommandUpdate.setDescription(description2); structureElementCommandUpdate.setComment(comment2); @@ -1918,6 +1920,7 @@ class StructuresDeviceGroupIT { ITUtilStructureElement.assertRead("/DEVICEGROUP?uuid=" + discipline2Uuid.toString(), 0); ITUtilStructureElement.assertRead("/DEVICEGROUP?uuid=" + uuid.toString(), 1); + ITUtilStructureElement.assertRead("/DEVICEGROUP?uuid=" + uuid2.toString(), 2); ITUtilStructureElement.assertRead("/DEVICEGROUP?parent=" + discipline2Uuid.toString(), 45, -1); ITUtilStructureElement.assertRead("/DEVICEGROUP?parent=" + uuid.toString(), 0); @@ -1941,6 +1944,17 @@ class StructuresDeviceGroupIT { ITUtilStructureElement.assertRead("/DEVICEGROUP?description=%sc%", 45, -1); ITUtilStructureElement.assertRead("/DEVICEGROUP?description=description", 35, -1); + ITUtilStructureElement.assertRead("/DEVICEGROUP?who=test who", 45, -1); + ITUtilStructureElement.assertRead("/DEVICEGROUP?who=test", 0); + ITUtilStructureElement.assertRead("/DEVICEGROUP?who=who", 0); + ITUtilStructureElement.assertRead("/DEVICEGROUP?who=test%", 45, -1); + ITUtilStructureElement.assertRead("/DEVICEGROUP?who=%who", 45, -1); + ITUtilStructureElement.assertRead("/DEVICEGROUP?who=%est%", 45, -1); + ITUtilStructureElement.assertRead("/DEVICEGROUP?who=%wh%", 45, -1); + ITUtilStructureElement.assertRead("/DEVICEGROUP?who=wh%", 0); + ITUtilStructureElement.assertRead("/DEVICEGROUP?who=asdf", 0); + ITUtilStructureElement.assertRead("/DEVICEGROUP?who=%asdf%", 0); + // children // /children/{uuid} // uuid, type, statuses, deleted, name, mnemonic, mnemonicEquivalence, mnemonicPath, description @@ -1972,6 +1986,24 @@ class StructuresDeviceGroupIT { ITUtilStructureElement.assertRead("/history/" + uuid.toString(), 2); ITUtilStructureElement.assertRead("/history/" + discipline2Uuid.toString(), 2); + // /history?parameter=value + // parameter must be available + ITUtilStructureElement.assertRead("/history?type=DEVICEGROUP&uuid=" + uuid.toString(), 2); + ITUtilStructureElement.assertRead("/history?type=DEVICEGROUP&uuid=" + uuid2.toString(), 8); + ITUtilStructureElement.assertRead("/history?type=DEVICEGROUP&uuid=" + discipline2Uuid.toString(), 0); + ITUtilStructureElement.assertRead("/history?uuid=" + uuid.toString(), 2); + ITUtilStructureElement.assertRead("/history?uuid=" + uuid2.toString(), 8); + ITUtilStructureElement.assertRead("/history?uuid=" + disciplineUuid.toString(), 2); + ITUtilStructureElement.assertRead("/history?parent=" + uuid.toString(), 0); + ITUtilStructureElement.assertRead("/history?parent=" + disciplineUuid.toString(), 32); + ITUtilStructureElement.assertRead("/history?name=na%", 120, -1); + ITUtilStructureElement.assertRead("/history?mnemonic=AF_", 0); + ITUtilStructureElement.assertRead("/history?mnemonicEquivalence=_A_", 0); + ITUtilStructureElement.assertRead("/history?description=%other%", 40); + ITUtilStructureElement.assertRead("/history?who=%wh%", 120, -1); + + ITUtilStructureElement.assertRead("/history?type=DEVICEGROUP&uuid=" + uuid2.toString() + "&description=more%", 8); + ITUtilStructureElement.assertExists(Type.DEVICEGROUP, "Di2", Boolean.FALSE); } catch (Exception e) { fail(); diff --git a/src/test/java/org/openepics/names/docker/StructuresDeviceTypeIT.java b/src/test/java/org/openepics/names/docker/StructuresDeviceTypeIT.java index 428c15c2b1fb6a93a36c43d07613423ca8080be2..a616491e68d375bb6b52c2d5542f58a3d8f0495b 100644 --- a/src/test/java/org/openepics/names/docker/StructuresDeviceTypeIT.java +++ b/src/test/java/org/openepics/names/docker/StructuresDeviceTypeIT.java @@ -1621,6 +1621,7 @@ class StructuresDeviceTypeIT { StructureElementCommandConfirm structureElementCommandConfirm = null; StructureElement createdStructureElement = null; UUID uuid = null; + UUID uuid2 = null; structureElementCommandCreate = new StructureElementCommandCreate( Type.DEVICETYPE, deviceGroupUuid, @@ -1738,6 +1739,7 @@ class StructuresDeviceTypeIT { "name", "AE1", "description", "comment"); createdStructureElement = ITUtilStructureElement.assertCreateApprove(structureElementCommandCreate); + uuid2 = createdStructureElement.getUuid(); structureElementCommandUpdate = StructureElementUtil.convertElement2CommandUpdate(createdStructureElement); structureElementCommandUpdate.setDescription(description2); structureElementCommandUpdate.setComment(comment2); @@ -1927,6 +1929,7 @@ class StructuresDeviceTypeIT { ITUtilStructureElement.assertRead("/DEVICETYPE?uuid=" + disciplineUuid.toString(), 0); ITUtilStructureElement.assertRead("/DEVICETYPE?uuid=" + deviceGroupUuid.toString(), 0); ITUtilStructureElement.assertRead("/DEVICETYPE?uuid=" + uuid.toString(), 1); + ITUtilStructureElement.assertRead("/DEVICETYPE?uuid=" + uuid2.toString(), 2); ITUtilStructureElement.assertRead("/DEVICETYPE?parent=" + disciplineUuid.toString(), 0); ITUtilStructureElement.assertRead("/DEVICETYPE?parent=" + deviceGroupUuid.toString(), 45, -1); @@ -1951,6 +1954,17 @@ class StructuresDeviceTypeIT { ITUtilStructureElement.assertRead("/DEVICETYPE?description=%sc%", 45, -1); ITUtilStructureElement.assertRead("/DEVICETYPE?description=description", 35, -1); + ITUtilStructureElement.assertRead("/DEVICETYPE?who=test who", 45, -1); + ITUtilStructureElement.assertRead("/DEVICETYPE?who=test", 0); + ITUtilStructureElement.assertRead("/DEVICETYPE?who=who", 0); + ITUtilStructureElement.assertRead("/DEVICETYPE?who=test%", 45, -1); + ITUtilStructureElement.assertRead("/DEVICETYPE?who=%who", 45, -1); + ITUtilStructureElement.assertRead("/DEVICETYPE?who=%est%", 45, -1); + ITUtilStructureElement.assertRead("/DEVICETYPE?who=%wh%", 45, -1); + ITUtilStructureElement.assertRead("/DEVICETYPE?who=wh%", 0); + ITUtilStructureElement.assertRead("/DEVICETYPE?who=asdf", 0); + ITUtilStructureElement.assertRead("/DEVICETYPE?who=%asdf%", 0); + // children // /children/{uuid} // uuid, type, statuses, deleted, name, mnemonic, mnemonicEquivalence, mnemonicPath, description @@ -1993,6 +2007,24 @@ class StructuresDeviceTypeIT { ITUtilStructureElement.assertRead("/history/" + deviceGroupUuid.toString(), 2); ITUtilStructureElement.assertRead("/history/" + disciplineUuid.toString(), 2); + // /history?parameter=value + // parameter must be available + ITUtilStructureElement.assertRead("/history?type=DEVICETYPE&uuid=" + uuid.toString(), 2); + ITUtilStructureElement.assertRead("/history?type=DEVICETYPE&uuid=" + uuid2.toString(), 8); + ITUtilStructureElement.assertRead("/history?type=DEVICETYPE&uuid=" + deviceGroupUuid.toString(), 0); + ITUtilStructureElement.assertRead("/history?uuid=" + uuid.toString(), 2); + ITUtilStructureElement.assertRead("/history?uuid=" + uuid2.toString(), 8); + ITUtilStructureElement.assertRead("/history?uuid=" + deviceGroupUuid.toString(), 2); + ITUtilStructureElement.assertRead("/history?parent=" + uuid.toString(), 0); + ITUtilStructureElement.assertRead("/history?parent=" + deviceGroupUuid.toString(), 120, -1); + ITUtilStructureElement.assertRead("/history?name=na%", 120, -1); + ITUtilStructureElement.assertRead("/history?mnemonic=AF_", 20); + ITUtilStructureElement.assertRead("/history?mnemonicEquivalence=_A_", 10); + ITUtilStructureElement.assertRead("/history?description=%other%", 40); + ITUtilStructureElement.assertRead("/history?who=%wh%", 120, -1); + + ITUtilStructureElement.assertRead("/history?type=DEVICETYPE&uuid=" + uuid2.toString() + "&description=more%", 8); + ITUtilStructureElement.assertExists(Type.DEVICETYPE, "Di-AA1", Boolean.TRUE); ITUtilStructureElement.assertExists(Type.DEVICETYPE, "Di-AA2", Boolean.TRUE); ITUtilStructureElement.assertExists(Type.DEVICETYPE, "Di-AA3", Boolean.TRUE); diff --git a/src/test/java/org/openepics/names/docker/StructuresDisciplineIT.java b/src/test/java/org/openepics/names/docker/StructuresDisciplineIT.java index df3cddeb79d9221bb60dd92d5697b64afabfa98c..3195b2709240b2a2b2e97c21523092c26fe47623 100644 --- a/src/test/java/org/openepics/names/docker/StructuresDisciplineIT.java +++ b/src/test/java/org/openepics/names/docker/StructuresDisciplineIT.java @@ -1518,6 +1518,8 @@ class StructuresDisciplineIT { StructureElementCommandConfirm structureElementCommandConfirm = null; StructureElement createdStructureElement = null; UUID uuid = null; + UUID uuid2 = null; + UUID uuidRandom = UUID.randomUUID(); structureElementCommandCreate = new StructureElementCommandCreate( Type.DISCIPLINE, null, @@ -1635,6 +1637,7 @@ class StructuresDisciplineIT { "name", "AE1", "description", "comment"); createdStructureElement = ITUtilStructureElement.assertCreateApprove(structureElementCommandCreate); + uuid2 = createdStructureElement.getUuid(); structureElementCommandUpdate = StructureElementUtil.convertElement2CommandUpdate(createdStructureElement); structureElementCommandUpdate.setDescription(description2); structureElementCommandUpdate.setComment(comment2); @@ -1821,7 +1824,9 @@ class StructuresDisciplineIT { ITUtilStructureElement.assertRead("/DISCIPLINE?deleted=true&statuses=REJECTED&mnemonic=A__", 5); ITUtilStructureElement.assertRead("/DISCIPLINE?deleted=true&statuses=PENDING&statuses=APPROVED&mnemonic=A__", 10); - ITUtilStructureElement.assertRead("/DISCIPLINE?uuid=" + uuid.toString(), 1); + ITUtilStructureElement.assertRead("/DISCIPLINE?uuid=" + uuid.toString(), 1); + ITUtilStructureElement.assertRead("/DISCIPLINE?uuid=" + uuid2.toString(), 2); + ITUtilStructureElement.assertRead("/DISCIPLINE?uuid=" + uuidRandom.toString(), 0); ITUtilStructureElement.assertRead("/DISCIPLINE?parent=" + uuid.toString(), 0); @@ -1844,6 +1849,17 @@ class StructuresDisciplineIT { ITUtilStructureElement.assertRead("/DISCIPLINE?description=%sc%", 45, -1); ITUtilStructureElement.assertRead("/DISCIPLINE?description=description", 35, -1); + ITUtilStructureElement.assertRead("/DISCIPLINE?who=test who", 45, -1); + ITUtilStructureElement.assertRead("/DISCIPLINE?who=test", 0); + ITUtilStructureElement.assertRead("/DISCIPLINE?who=who", 0); + ITUtilStructureElement.assertRead("/DISCIPLINE?who=test%", 45, -1); + ITUtilStructureElement.assertRead("/DISCIPLINE?who=%who", 45, -1); + ITUtilStructureElement.assertRead("/DISCIPLINE?who=%est%", 45, -1); + ITUtilStructureElement.assertRead("/DISCIPLINE?who=%wh%", 45, -1); + ITUtilStructureElement.assertRead("/DISCIPLINE?who=wh%", 0); + ITUtilStructureElement.assertRead("/DISCIPLINE?who=asdf", 0); + ITUtilStructureElement.assertRead("/DISCIPLINE?who=%asdf%", 0); + // children // /children/{uuid} // uuid, type, statuses, deleted, name, mnemonic, mnemonicEquivalence, mnemonicPath, description @@ -1866,7 +1882,26 @@ class StructuresDisciplineIT { // history // /history/{uuid} - ITUtilStructureElement.assertRead("/history/" + uuid.toString(), 2); + ITUtilStructureElement.assertRead("/history/" + uuid.toString(), 2); + ITUtilStructureElement.assertRead("/history/" + uuid2.toString(), 8); + ITUtilStructureElement.assertRead("/history/" + uuidRandom.toString(), 0); + + // /history?parameter=value + // parameter must be available + ITUtilStructureElement.assertRead("/history?type=DISCIPLINE&uuid=" + uuid.toString(), 2); + ITUtilStructureElement.assertRead("/history?type=DISCIPLINE&uuid=" + uuid2.toString(), 8); + ITUtilStructureElement.assertRead("/history?type=DISCIPLINE&uuid=" + uuidRandom.toString(), 0); + ITUtilStructureElement.assertRead("/history?uuid=" + uuid.toString(), 2); + ITUtilStructureElement.assertRead("/history?uuid=" + uuid2.toString(), 8); + ITUtilStructureElement.assertRead("/history?uuid=" + uuidRandom.toString(), 0); + ITUtilStructureElement.assertRead("/history?parent=" + uuid.toString(), 0); + ITUtilStructureElement.assertRead("/history?name=na%", 120, -1); + ITUtilStructureElement.assertRead("/history?mnemonic=AF_", 20); + ITUtilStructureElement.assertRead("/history?mnemonicEquivalence=_A_", 10); + ITUtilStructureElement.assertRead("/history?description=%other%", 40); + ITUtilStructureElement.assertRead("/history?who=%wh%", 120, -1); + + ITUtilStructureElement.assertRead("/history?type=DISCIPLINE&uuid=" + uuid2.toString() + "&description=more%", 8); ITUtilStructureElement.assertExists(Type.DISCIPLINE, "AA1", Boolean.TRUE); ITUtilStructureElement.assertExists(Type.DISCIPLINE, "AA2", Boolean.TRUE); diff --git a/src/test/java/org/openepics/names/docker/StructuresSubsystemIT.java b/src/test/java/org/openepics/names/docker/StructuresSubsystemIT.java index 179db02471b1cbba7f1480cc3a7dca7fb50196a1..2071c746bfeba93bac8dbf5d9a4f65feb0460ed0 100644 --- a/src/test/java/org/openepics/names/docker/StructuresSubsystemIT.java +++ b/src/test/java/org/openepics/names/docker/StructuresSubsystemIT.java @@ -1669,6 +1669,7 @@ class StructuresSubsystemIT { StructureElementCommandConfirm structureElementCommandConfirm = null; StructureElement createdStructureElement = null; UUID uuid = null; + UUID uuid2 = null; structureElementCommandCreate = new StructureElementCommandCreate( Type.SUBSYSTEM, systemUuid, @@ -1786,6 +1787,7 @@ class StructuresSubsystemIT { "name", "AE1", "description", "comment"); createdStructureElement = ITUtilStructureElement.assertCreateApprove(structureElementCommandCreate); + uuid2 = createdStructureElement.getUuid(); structureElementCommandUpdate = StructureElementUtil.convertElement2CommandUpdate(createdStructureElement); structureElementCommandUpdate.setDescription(description2); structureElementCommandUpdate.setComment(comment2); @@ -1975,6 +1977,7 @@ class StructuresSubsystemIT { ITUtilStructureElement.assertRead("/SUBSYSTEM?uuid=" + systemGroupUuid.toString(), 0); ITUtilStructureElement.assertRead("/SUBSYSTEM?uuid=" + systemUuid.toString(), 0); ITUtilStructureElement.assertRead("/SUBSYSTEM?uuid=" + uuid.toString(), 1); + ITUtilStructureElement.assertRead("/SUBSYSTEM?uuid=" + uuid2.toString(), 2); ITUtilStructureElement.assertRead("/SUBSYSTEM?parent=" + systemGroupUuid.toString(), 0); ITUtilStructureElement.assertRead("/SUBSYSTEM?parent=" + systemUuid.toString(), 45, -1); @@ -1999,6 +2002,17 @@ class StructuresSubsystemIT { ITUtilStructureElement.assertRead("/SUBSYSTEM?description=%sc%", 45, -1); ITUtilStructureElement.assertRead("/SUBSYSTEM?description=description", 35, -1); + ITUtilStructureElement.assertRead("/SUBSYSTEM?who=test who", 45, -1); + ITUtilStructureElement.assertRead("/SUBSYSTEM?who=test", 0); + ITUtilStructureElement.assertRead("/SUBSYSTEM?who=who", 0); + ITUtilStructureElement.assertRead("/SUBSYSTEM?who=test%", 45, -1); + ITUtilStructureElement.assertRead("/SUBSYSTEM?who=%who", 45, -1); + ITUtilStructureElement.assertRead("/SUBSYSTEM?who=%est%", 45, -1); + ITUtilStructureElement.assertRead("/SUBSYSTEM?who=%wh%", 45, -1); + ITUtilStructureElement.assertRead("/SUBSYSTEM?who=wh%", 0); + ITUtilStructureElement.assertRead("/SUBSYSTEM?who=asdf", 0); + ITUtilStructureElement.assertRead("/SUBSYSTEM?who=%asdf%", 0); + // children // /children/{uuid} // uuid, type, statuses, deleted, name, mnemonic, mnemonicEquivalence, mnemonicPath, description @@ -2051,6 +2065,24 @@ class StructuresSubsystemIT { ITUtilStructureElement.assertRead("/history/" + systemUuid.toString(), 2); ITUtilStructureElement.assertRead("/history/" + systemGroupUuid.toString(), 2); + // /history?parameter=value + // parameter must be available + ITUtilStructureElement.assertRead("/history?type=SUBSYSTEM&uuid=" + uuid.toString(), 2); + ITUtilStructureElement.assertRead("/history?type=SUBSYSTEM&uuid=" + uuid2.toString(), 8); + ITUtilStructureElement.assertRead("/history?type=SUBSYSTEM&uuid=" + systemUuid.toString(), 0); + ITUtilStructureElement.assertRead("/history?uuid=" + uuid.toString(), 2); + ITUtilStructureElement.assertRead("/history?uuid=" + uuid2.toString(), 8); + ITUtilStructureElement.assertRead("/history?uuid=" + systemUuid.toString(), 2); + ITUtilStructureElement.assertRead("/history?parent=" + uuid.toString(), 0); + ITUtilStructureElement.assertRead("/history?parent=" + systemUuid.toString(), 142); + ITUtilStructureElement.assertRead("/history?name=na%", 120, -1); + ITUtilStructureElement.assertRead("/history?mnemonic=AF_", 20); + ITUtilStructureElement.assertRead("/history?mnemonicEquivalence=_A_", 10); + ITUtilStructureElement.assertRead("/history?description=%other%", 40); + ITUtilStructureElement.assertRead("/history?who=%wh%", 120, -1); + + ITUtilStructureElement.assertRead("/history?type=SUBSYSTEM&uuid=" + uuid2.toString() + "&description=more%", 8); + ITUtilStructureElement.assertExists(Type.SUBSYSTEM, "Sys-AA1", Boolean.TRUE); ITUtilStructureElement.assertExists(Type.SUBSYSTEM, "Sys-AA2", Boolean.TRUE); ITUtilStructureElement.assertExists(Type.SUBSYSTEM, "Sys-AA3", Boolean.TRUE); diff --git a/src/test/java/org/openepics/names/docker/StructuresSystemGroupIT.java b/src/test/java/org/openepics/names/docker/StructuresSystemGroupIT.java index 739e431568463b7f5f556450ea20a3dff7f6d554..1ffb9382cbc2f582a71e2498cce11cf17b3e68c9 100644 --- a/src/test/java/org/openepics/names/docker/StructuresSystemGroupIT.java +++ b/src/test/java/org/openepics/names/docker/StructuresSystemGroupIT.java @@ -1580,6 +1580,8 @@ class StructuresSystemGroupIT { StructureElementCommandConfirm structureElementCommandConfirm = null; StructureElement createdStructureElement = null; UUID uuid = null; + UUID uuid2 = null; + UUID uuidRandom = UUID.randomUUID(); structureElementCommandCreate = new StructureElementCommandCreate( Type.SYSTEMGROUP, null, @@ -1697,6 +1699,7 @@ class StructuresSystemGroupIT { "name", "AE1", "description", "comment"); createdStructureElement = ITUtilStructureElement.assertCreateApprove(structureElementCommandCreate); + uuid2 = createdStructureElement.getUuid(); structureElementCommandUpdate = StructureElementUtil.convertElement2CommandUpdate(createdStructureElement); structureElementCommandUpdate.setDescription(description2); structureElementCommandUpdate.setComment(comment2); @@ -1883,7 +1886,9 @@ class StructuresSystemGroupIT { ITUtilStructureElement.assertRead("/SYSTEMGROUP?deleted=true&statuses=REJECTED&mnemonic=A__", 5); ITUtilStructureElement.assertRead("/SYSTEMGROUP?deleted=true&statuses=PENDING&statuses=APPROVED&mnemonic=A__", 10); - ITUtilStructureElement.assertRead("/SYSTEMGROUP?uuid=" + uuid.toString(), 1); + ITUtilStructureElement.assertRead("/SYSTEMGROUP?uuid=" + uuid.toString(), 1); + ITUtilStructureElement.assertRead("/SYSTEMGROUP?uuid=" + uuid2.toString(), 2); + ITUtilStructureElement.assertRead("/SYSTEMGROUP?uuid=" + uuidRandom.toString(), 0); ITUtilStructureElement.assertRead("/SYSTEMGROUP?parent=" + uuid.toString(), 0); @@ -1906,6 +1911,17 @@ class StructuresSystemGroupIT { ITUtilStructureElement.assertRead("/SYSTEMGROUP?description=%sc%", 45, -1); ITUtilStructureElement.assertRead("/SYSTEMGROUP?description=description", 35, -1); + ITUtilStructureElement.assertRead("/SYSTEMGROUP?who=test who", 45, -1); + ITUtilStructureElement.assertRead("/SYSTEMGROUP?who=test", 0); + ITUtilStructureElement.assertRead("/SYSTEMGROUP?who=who", 0); + ITUtilStructureElement.assertRead("/SYSTEMGROUP?who=test%", 45, -1); + ITUtilStructureElement.assertRead("/SYSTEMGROUP?who=%who", 45, -1); + ITUtilStructureElement.assertRead("/SYSTEMGROUP?who=%est%", 45, -1); + ITUtilStructureElement.assertRead("/SYSTEMGROUP?who=%wh%", 45, -1); + ITUtilStructureElement.assertRead("/SYSTEMGROUP?who=wh%", 0); + ITUtilStructureElement.assertRead("/SYSTEMGROUP?who=asdf", 0); + ITUtilStructureElement.assertRead("/SYSTEMGROUP?who=%asdf%", 0); + // children // /children/{uuid} // uuid, type, statuses, deleted, name, mnemonic, mnemonicEquivalence, mnemonicPath, description @@ -1928,7 +1944,26 @@ class StructuresSystemGroupIT { // history // /history/{uuid} - ITUtilStructureElement.assertRead("/history/" + uuid.toString(), 2); + ITUtilStructureElement.assertRead("/history/" + uuid.toString(), 2); + ITUtilStructureElement.assertRead("/history/" + uuid2.toString(), 8); + ITUtilStructureElement.assertRead("/history/" + uuidRandom.toString(), 0); + + // /history?parameter=value + // parameter must be available + ITUtilStructureElement.assertRead("/history?type=SYSTEMGROUP&uuid=" + uuid.toString(), 2); + ITUtilStructureElement.assertRead("/history?type=SYSTEMGROUP&uuid=" + uuid2.toString(), 8); + ITUtilStructureElement.assertRead("/history?type=SYSTEMGROUP&uuid=" + uuidRandom.toString(), 0); + ITUtilStructureElement.assertRead("/history?uuid=" + uuid.toString(), 2); + ITUtilStructureElement.assertRead("/history?uuid=" + uuid2.toString(), 8); + ITUtilStructureElement.assertRead("/history?uuid=" + uuidRandom.toString(), 0); + ITUtilStructureElement.assertRead("/history?parent=" + uuid.toString(), 0); + ITUtilStructureElement.assertRead("/history?name=na%", 120, -1); + ITUtilStructureElement.assertRead("/history?mnemonic=AF_", 20); + ITUtilStructureElement.assertRead("/history?mnemonicEquivalence=_A_", 10); + ITUtilStructureElement.assertRead("/history?description=%other%", 40); + ITUtilStructureElement.assertRead("/history?who=%wh%", 120, -1); + + ITUtilStructureElement.assertRead("/history?type=SYSTEMGROUP&uuid=" + uuid2.toString() + "&description=more%", 8); ITUtilStructureElement.assertExists(Type.SYSTEMGROUP, "AA1", Boolean.TRUE); ITUtilStructureElement.assertExists(Type.SYSTEMGROUP, "AA2", Boolean.TRUE); diff --git a/src/test/java/org/openepics/names/docker/StructuresSystemIT.java b/src/test/java/org/openepics/names/docker/StructuresSystemIT.java index df29fcf62b1b6dff8995ccce05b44fc2a6c2b923..8e36cd619843eabc9879d625deb7fc78c0322368 100644 --- a/src/test/java/org/openepics/names/docker/StructuresSystemIT.java +++ b/src/test/java/org/openepics/names/docker/StructuresSystemIT.java @@ -1602,6 +1602,7 @@ class StructuresSystemIT { StructureElementCommandConfirm structureElementCommandConfirm = null; StructureElement createdStructureElement = null; UUID uuid = null; + UUID uuid2 = null; structureElementCommandCreate = new StructureElementCommandCreate( Type.SYSTEM, systemGroupUuid, @@ -1719,6 +1720,7 @@ class StructuresSystemIT { "name", "AE1", "description", "comment"); createdStructureElement = ITUtilStructureElement.assertCreateApprove(structureElementCommandCreate); + uuid2 = createdStructureElement.getUuid(); structureElementCommandUpdate = StructureElementUtil.convertElement2CommandUpdate(createdStructureElement); structureElementCommandUpdate.setDescription(description2); structureElementCommandUpdate.setComment(comment2); @@ -1907,6 +1909,7 @@ class StructuresSystemIT { ITUtilStructureElement.assertRead("/SYSTEM?uuid=" + systemGroupUuid.toString(), 0); ITUtilStructureElement.assertRead("/SYSTEM?uuid=" + uuid.toString(), 1); + ITUtilStructureElement.assertRead("/SYSTEM?uuid=" + uuid2.toString(), 2); ITUtilStructureElement.assertRead("/SYSTEM?parent=" + systemGroupUuid.toString(), 45, -1); ITUtilStructureElement.assertRead("/SYSTEM?parent=" + uuid.toString(), 0); @@ -1930,6 +1933,17 @@ class StructuresSystemIT { ITUtilStructureElement.assertRead("/SYSTEM?description=%sc%", 45, -1); ITUtilStructureElement.assertRead("/SYSTEM?description=description", 35, -1); + ITUtilStructureElement.assertRead("/SYSTEM?who=test who", 45, -1); + ITUtilStructureElement.assertRead("/SYSTEM?who=test", 0); + ITUtilStructureElement.assertRead("/SYSTEM?who=who", 0); + ITUtilStructureElement.assertRead("/SYSTEM?who=test%", 45, -1); + ITUtilStructureElement.assertRead("/SYSTEM?who=%who", 45, -1); + ITUtilStructureElement.assertRead("/SYSTEM?who=%est%", 45, -1); + ITUtilStructureElement.assertRead("/SYSTEM?who=%wh%", 45, -1); + ITUtilStructureElement.assertRead("/SYSTEM?who=wh%", 0); + ITUtilStructureElement.assertRead("/SYSTEM?who=asdf", 0); + ITUtilStructureElement.assertRead("/SYSTEM?who=%asdf%", 0); + // children // /children/{uuid} // uuid, type, statuses, deleted, name, mnemonic, mnemonicEquivalence, mnemonicPath, description @@ -1965,6 +1979,24 @@ class StructuresSystemIT { ITUtilStructureElement.assertRead("/history/" + uuid.toString(), 2); ITUtilStructureElement.assertRead("/history/" + systemGroupUuid.toString(), 2); + // /history?parameter=value + // parameter must be available + ITUtilStructureElement.assertRead("/history?type=SYSTEM&uuid=" + uuid.toString(), 2); + ITUtilStructureElement.assertRead("/history?type=SYSTEM&uuid=" + uuid2.toString(), 8); + ITUtilStructureElement.assertRead("/history?type=SYSTEM&uuid=" + systemGroupUuid.toString(), 0); + ITUtilStructureElement.assertRead("/history?uuid=" + uuid.toString(), 2); + ITUtilStructureElement.assertRead("/history?uuid=" + uuid2.toString(), 8); + ITUtilStructureElement.assertRead("/history?uuid=" + systemGroupUuid.toString(), 2); + ITUtilStructureElement.assertRead("/history?parent=" + uuid.toString(), 0); + ITUtilStructureElement.assertRead("/history?parent=" + systemGroupUuid.toString(), 142); + ITUtilStructureElement.assertRead("/history?name=na%", 120, -1); + ITUtilStructureElement.assertRead("/history?mnemonic=AF_", 20); + ITUtilStructureElement.assertRead("/history?mnemonicEquivalence=_A_", 10); + ITUtilStructureElement.assertRead("/history?description=%other%", 40); + ITUtilStructureElement.assertRead("/history?who=%wh%", 120, -1); + + ITUtilStructureElement.assertRead("/history?type=SYSTEM&uuid=" + uuid2.toString() + "&description=more%", 8); + ITUtilStructureElement.assertExists(Type.SYSTEM, "AA1", Boolean.TRUE); ITUtilStructureElement.assertExists(Type.SYSTEM, "AA2", Boolean.TRUE); ITUtilStructureElement.assertExists(Type.SYSTEM, "AA3", Boolean.TRUE); diff --git a/src/test/java/org/openepics/names/util/ValidateUtilTest.java b/src/test/java/org/openepics/names/util/ValidateUtilTest.java index 82822acbe9cb962d1c8b9bdc2d3f8e9b1580ca12..5a4089cc692fe7fc7ecb628dcd7fa2d68d94ccff 100644 --- a/src/test/java/org/openepics/names/util/ValidateUtilTest.java +++ b/src/test/java/org/openepics/names/util/ValidateUtilTest.java @@ -722,7 +722,7 @@ class ValidateUtilTest { try { ValidateStructureElementUtil.validateStructuresInputRead( null, null, null, - null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, null, null, null); fail(); } catch (InputNotAvailableException e) { @@ -738,27 +738,27 @@ class ValidateUtilTest { void validateInputReadStructures() { ValidateStructureElementUtil.validateStructuresInputRead( Type.SYSTEMGROUP, null, null, - null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, null, null, null); ValidateStructureElementUtil.validateStructuresInputRead( Type.SYSTEM, null, null, - null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, null, null, null); ValidateStructureElementUtil.validateStructuresInputRead( Type.SUBSYSTEM, null, null, - null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, null, null, null); ValidateStructureElementUtil.validateStructuresInputRead( Type.DISCIPLINE, null, null, - null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, null, null, null); ValidateStructureElementUtil.validateStructuresInputRead( Type.DEVICEGROUP, null, null, - null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, null, null, null); ValidateStructureElementUtil.validateStructuresInputRead( Type.DEVICETYPE, null, null, - null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, null, null, null); }