Skip to content
Snippets Groups Projects
Commit 90d9d9c6 authored by Lars Johansson's avatar Lars Johansson
Browse files

Fix issues in validation and add integration tests for multiple name and structure elements

Fix issues in validation.
Add integration tests for multiple name elements - create, update, delete.
Add integration tests for multiple structure elements - create, update, delete, approve, cancel, reject.
parent b48cc51f
No related branches found
No related tags found
No related merge requests found
......@@ -26,6 +26,9 @@ import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.openepics.names.repository.DeviceGroupRepository;
import org.openepics.names.repository.DeviceTypeRepository;
import org.openepics.names.repository.DisciplineRepository;
import org.openepics.names.repository.IDeviceGroupRepository;
import org.openepics.names.repository.IDeviceTypeRepository;
import org.openepics.names.repository.IDisciplineRepository;
......@@ -34,6 +37,9 @@ import org.openepics.names.repository.ISubsystemRepository;
import org.openepics.names.repository.ISystemGroupRepository;
import org.openepics.names.repository.ISystemRepository;
import org.openepics.names.repository.NameRepository;
import org.openepics.names.repository.SubsystemRepository;
import org.openepics.names.repository.SystemGroupRepository;
import org.openepics.names.repository.SystemRepository;
import org.openepics.names.repository.model.DeviceGroup;
import org.openepics.names.repository.model.DeviceType;
import org.openepics.names.repository.model.Discipline;
......@@ -49,6 +55,7 @@ import org.openepics.names.rest.beans.response.ResponsePageNameElements;
import org.openepics.names.util.EssNamingConvention;
import org.openepics.names.util.ExceptionUtil;
import org.openepics.names.util.HolderIRepositories;
import org.openepics.names.util.HolderRepositories;
import org.openepics.names.util.HolderSystemDeviceStructure;
import org.openepics.names.util.NameElementUtil;
import org.openepics.names.util.NameUtil;
......@@ -83,6 +90,8 @@ public class NamesService {
private EssNamingConvention namingConvention;
private HolderIRepositories holderIRepositories;
private HolderRepositories holderRepositories;
// convenience, also part of holderRepositories
private NameRepository nameRepository;
@Autowired
......@@ -94,7 +103,13 @@ public class NamesService {
IDisciplineRepository iDisciplineRepository,
IDeviceGroupRepository iDeviceGroupRepository,
IDeviceTypeRepository iDeviceTypeRepository,
NameRepository nameRepository) {
NameRepository nameRepository,
SystemGroupRepository systemGroupRepository,
SystemRepository systemRepository,
SubsystemRepository subsystemRepository,
DisciplineRepository disciplineRepository,
DeviceGroupRepository deviceGroupRepository,
DeviceTypeRepository deviceTypeRepository) {
this.namingConvention = new EssNamingConvention();
this.holderIRepositories = new HolderIRepositories(
......@@ -105,6 +120,14 @@ public class NamesService {
iDisciplineRepository,
iDeviceGroupRepository,
iDeviceTypeRepository);
this.holderRepositories = new HolderRepositories(
nameRepository,
systemGroupRepository,
systemRepository,
subsystemRepository,
disciplineRepository,
deviceGroupRepository,
deviceTypeRepository);
this.nameRepository = nameRepository;
}
......@@ -129,12 +152,16 @@ public class NamesService {
String requestedBy = "test who";
final List<NameElement> createdNameElements = Lists.newArrayList();
for (NameElementCommand nameElement : nameElements) {
// find out system group, system, subsystem
// one of the three expected to be non-null, other two expected to be null
// find out
// system structure - system group, system, subsystem - one of the three expected to be non-null, other two expected to be null
// device structure - device type - may be null
SystemGroup systemGroup = holderIRepositories.getSystemGroupRepository().findLatestByUuid(nameElement.getParentsystemstructure().toString());
System system = holderIRepositories.getSystemRepository().findLatestByUuid(nameElement.getParentsystemstructure().toString());
Subsystem subsystem = holderIRepositories.getSubsystemRepository().findLatestByUuid(nameElement.getParentsystemstructure().toString());
DeviceType deviceType = holderIRepositories.getDeviceTypeRepository().findLatestByUuid(nameElement.getParentdevicestructure().toString());
DeviceType deviceType = null;
if (nameElement.getParentdevicestructure() != null) {
deviceType = holderIRepositories.getDeviceTypeRepository().findLatestByUuid(nameElement.getParentdevicestructure().toString());
}
String derivedName = null;
if (systemGroup != null) {
......@@ -471,7 +498,7 @@ public class NamesService {
HolderSystemDeviceStructure holder = new HolderSystemDeviceStructure(holderIRepositories, false);
// validate data
ValidateUtil.validateNameDataCreate(name, namingConvention, holderIRepositories, nameRepository, holder);
ValidateUtil.validateNameDataCreate(name, namingConvention, holderRepositories, holder);
return Boolean.TRUE;
}
......@@ -620,7 +647,10 @@ public class NamesService {
SystemGroup systemGroup = holderIRepositories.getSystemGroupRepository().findLatestByUuid(nameElement.getParentsystemstructure().toString());
System system = holderIRepositories.getSystemRepository().findLatestByUuid(nameElement.getParentsystemstructure().toString());
Subsystem subsystem = holderIRepositories.getSubsystemRepository().findLatestByUuid(nameElement.getParentsystemstructure().toString());
DeviceType deviceType = holderIRepositories.getDeviceTypeRepository().findLatestByUuid(nameElement.getParentdevicestructure().toString());
DeviceType deviceType = null;
if (nameElement.getParentdevicestructure() != null) {
deviceType = holderIRepositories.getDeviceTypeRepository().findLatestByUuid(nameElement.getParentdevicestructure().toString());
}
String derivedName = null;
if (systemGroup != null) {
......@@ -688,7 +718,10 @@ public class NamesService {
SystemGroup systemGroup = holderIRepositories.getSystemGroupRepository().findLatestByUuid(nameElement.getParentsystemstructure().toString());
System system = holderIRepositories.getSystemRepository().findLatestByUuid(nameElement.getParentsystemstructure().toString());
Subsystem subsystem = holderIRepositories.getSubsystemRepository().findLatestByUuid(nameElement.getParentsystemstructure().toString());
DeviceType deviceType = holderIRepositories.getDeviceTypeRepository().findLatestByUuid(nameElement.getParentdevicestructure().toString());
DeviceType deviceType = null;
if (nameElement.getParentdevicestructure() != null) {
deviceType = holderIRepositories.getDeviceTypeRepository().findLatestByUuid(nameElement.getParentdevicestructure().toString());
}
String derivedName = null;
if (systemGroup != null) {
......
......@@ -150,10 +150,14 @@ public class NameElementUtil {
// find out system group, system, subsystem
// one of the three expected to be non-null, other two expected to be null
SystemGroup systemGroup = holderIRepositories.getSystemGroupRepository().findLatestByUuid(nameElement.getParentsystemstructure().toString());
System system = holderIRepositories.getSystemRepository().findLatestByUuid(nameElement.getParentsystemstructure().toString());
Subsystem subsystem = holderIRepositories.getSubsystemRepository().findLatestByUuid(nameElement.getParentsystemstructure().toString());
DeviceType deviceType = holderIRepositories.getDeviceTypeRepository().findLatestByUuid(nameElement.getParentdevicestructure().toString());
DeviceType deviceType = null;
if (nameElement.getParentdevicestructure() != null) {
deviceType = holderIRepositories.getDeviceTypeRepository().findLatestByUuid(nameElement.getParentdevicestructure().toString());
}
String derivedName = null;
if (systemGroup != null) {
......
......@@ -107,6 +107,7 @@ public class TextUtil {
public static final String DEVICEGROUP_IS_NOT_AVAILABLE = DEVICEGROUP + SPACE + IS_NOT_AVAILABLE;
public static final String DEVICETYPE_IS_NOT_AVAILABLE = DEVICETYPE + SPACE + IS_NOT_AVAILABLE;
public static final String PARENT_IS_NOT_CORRECT = PARENT + SPACE + IS_NOT_CORRECT;
public static final String SYSTEM_STRUCTURE_IS_NOT_CORRECT = SYSTEM_STRUCTURE + SPACE + IS_NOT_CORRECT;
public static final String SYSTEMGROUP_IS_NOT_CORRECT = SYSTEMGROUP + SPACE + IS_NOT_CORRECT;
public static final String SYSTEM_IS_NOT_CORRECT = SYSTEM + SPACE + IS_NOT_CORRECT;
......
......@@ -454,15 +454,12 @@ public class ValidateUtil {
// system structure
if (systemGroup != null) {
ExceptionUtil.validateConditionDataDeletedException(!systemGroup.isDeleted(), TextUtil.DATA_IS_DELETED, details, TextUtil.PARENTSYSTEMSTRUCTURE);
derivedName = NameUtil.getName(systemGroup, deviceType, nameElement.getIndex(), holder);
} else if (system != null) {
ExceptionUtil.validateConditionDataDeletedException(!system.isDeleted(), TextUtil.DATA_IS_DELETED, details, TextUtil.PARENTSYSTEMSTRUCTURE);
derivedName = NameUtil.getName(system, deviceType, nameElement.getIndex(), holder);
} else if (subsystem != null) {
ExceptionUtil.validateConditionDataDeletedException(!subsystem.isDeleted(), TextUtil.DATA_IS_DELETED, details, TextUtil.PARENTSYSTEMSTRUCTURE);
derivedName = NameUtil.getName(subsystem, deviceType, nameElement.getIndex(), holder);
} else {
throw ExceptionUtil.createDataNotCorrectException(TextUtil.DATA_IS_NOT_CORRECT, details, TextUtil.PARENTSYSTEMSTRUCTURE);
......@@ -513,14 +510,13 @@ public class ValidateUtil {
*
* @param name name
* @param namingConvention naming convention
* @param holderIRepositories holder repositories
* @param nameRepository name repository
* @param holderRepositories holder repositories
* @param holder holder
*
* @see ValidateUtil#validateNameDataCreate(NameElement, EssNamingConvention, HolderIRepositories, NameRepository, HolderSystemDeviceStructure)
*/
public static void validateNameDataCreate(String name, EssNamingConvention namingConvention, HolderIRepositories holderIRepositories, NameRepository nameRepository, HolderSystemDeviceStructure holder) {
if (name == null || namingConvention == null || holderIRepositories == null || nameRepository == null || holder == null) {
public static void validateNameDataCreate(String name, EssNamingConvention namingConvention, HolderRepositories holderRepositories, HolderSystemDeviceStructure holder) {
if (name == null || namingConvention == null || holderRepositories == null || holder == null) {
return;
}
......@@ -538,6 +534,9 @@ public class ValidateUtil {
String dt = NamingConventionUtil.extractDeviceType(name);
String idx = NamingConventionUtil.extractInstanceIndex(name);
String mnemonicPathSystemstructure = NamingConventionUtil.extractMnemonicPathSystemStructure(name);
String mnemonicPathDevicestructure = NamingConventionUtil.extractMnemonicPathDeviceStructure(name);
int count = 0;
int countSgSys = 0;
int countSgSub = 0;
......@@ -554,6 +553,7 @@ public class ValidateUtil {
count++;
countSgSub++;
}
// one or two system structure mnemonics + not system group and system + not system group and subsystem
if (count < 1 || count > 2 || countSgSys == 2 || countSgSub == 2) {
throw ExceptionUtil.createDataNotCorrectException(TextUtil.SYSTEM_STRUCTURE_IS_NOT_CORRECT, details, field);
......@@ -577,34 +577,27 @@ public class ValidateUtil {
// device structure
if (!StringUtils.isEmpty(dt)) {
deviceType = holderIRepositories.getDeviceTypeRepository().findLatestNotDeletedByMnemonic(dt);
ExceptionUtil.validateConditionDataNotAvailableException(deviceType != null, TextUtil.DEVICETYPE_IS_NOT_AVAILABLE, details, field);
List<DeviceType> deviceTypes = holderRepositories.getDeviceTypeRepository().readDeviceTypes(Status.APPROVED, false, FieldStructure.MNEMONICPATH, mnemonicPathDevicestructure);
ExceptionUtil.validateConditionDataNotAvailableException(deviceTypes != null && deviceTypes.size() == 1, TextUtil.DEVICETYPE_IS_NOT_AVAILABLE, details, field);
deviceType = deviceTypes.get(0);
}
// system structure
if (!StringUtils.isEmpty(sg)) {
systemGroup = holderIRepositories.getSystemGroupRepository().findLatestNotDeletedByMnemonic(sg);
ExceptionUtil.validateConditionDataNotAvailableException(systemGroup != null, TextUtil.SYSTEMGROUP_IS_NOT_AVAILABLE, details, field);
List<Subsystem> subsystems = holderRepositories.getSubsystemRepository().readSubsystems(Status.APPROVED, false, FieldStructure.MNEMONICPATH, mnemonicPathSystemstructure);
List<System> systems = holderRepositories.getSystemRepository().readSystems(Status.APPROVED, false, FieldStructure.MNEMONICPATH, mnemonicPathSystemstructure);
List<SystemGroup> systemGroups = holderRepositories.getSystemGroupRepository().readSystemGroups(Status.APPROVED, false, FieldStructure.MNEMONICPATH, mnemonicPathSystemstructure);
if (subsystems != null && subsystems.size() == 1) {
subsystem = subsystems.get(0);
derivedName = NameUtil.getName(subsystem, deviceType, NamingConventionUtil.extractInstanceIndex(name), holder);
} else if (systems != null && systems.size() == 1) {
system = systems.get(0);
derivedName = NameUtil.getName(system, deviceType, NamingConventionUtil.extractInstanceIndex(name), holder);
} else if (systemGroups != null && systemGroups.size() == 1) {
systemGroup = systemGroups.get(0);
derivedName = NameUtil.getName(systemGroup, deviceType, NamingConventionUtil.extractInstanceIndex(name), holder);
} else {
if (!StringUtils.isEmpty(sys)) {
system = holderIRepositories.getSystemRepository().findLatestNotDeletedByMnemonic(sys);
ExceptionUtil.validateConditionDataNotAvailableException(system != null, TextUtil.SYSTEM_IS_NOT_AVAILABLE, details, field);
derivedName = NameUtil.getName(system, deviceType, NamingConventionUtil.extractInstanceIndex(name), holder);
} else {
throw ExceptionUtil.createDataNotAvailableException(
TextUtil.SYSTEM_IS_NOT_AVAILABLE, details, field);
}
// TODO is this condition correct?
ExceptionUtil.validateConditionDataNotAvailableException(system != null, TextUtil.SYSTEM_IS_NOT_AVAILABLE, details, field);
if (!StringUtils.isEmpty(sub)) {
subsystem = holderIRepositories.getSubsystemRepository().findLatestNotDeletedByParentAndMnemonic(system.getUuid().toString(), sub);
ExceptionUtil.validateConditionDataNotAvailableException(subsystem != null, TextUtil.SUBSYSTEM_IS_NOT_AVAILABLE, details, field);
derivedName = NameUtil.getName(subsystem, deviceType, NamingConventionUtil.extractInstanceIndex(name), holder);
}
} else {
throw ExceptionUtil.createDataNotCorrectException(TextUtil.SYSTEM_STRUCTURE_IS_NOT_CORRECT, details, field);
}
// index
......@@ -619,10 +612,10 @@ public class ValidateUtil {
// convention name equivalence not exists
ExceptionUtil.validateConditionDataNotCorrectException(StringUtils.equals(name, derivedName), TextUtil.CONVENTION_NAME_IS_NOT_CORRECT, details, field);
List<Name> names = nameRepository.readNames(false, FieldName.NAME, name);
List<Name> names = holderRepositories.getNameRepository().readNames(false, FieldName.NAME, name);
ExceptionUtil.validateConditionDataExistException(names.isEmpty(), TextUtil.CONVENTION_NAME_EXISTS, details, field);
names = nameRepository.readNames(false, FieldName.NAMEEQUIVALENCE, namingConvention.equivalenceClassRepresentative(name));
names = holderRepositories.getNameRepository().readNames(false, FieldName.NAMEEQUIVALENCE, namingConvention.equivalenceClassRepresentative(name));
ExceptionUtil.validateConditionDataExistException(names.isEmpty(), TextUtil.CONVENTION_NAME_EQUIVALENCE_EXISTS, details, field);
}
......@@ -889,13 +882,18 @@ public class ValidateUtil {
String field = TextUtil.UUID;
// validate data in itself
// systemgroup, discipline
// not have parent
// update, delete
// entry not pending
// entry approved and not deleted
// approve, cancel, reject
// entry pending
if (StructureChoice.UPDATE.equals(structureChoice) || StructureChoice.DELETE.equals(structureChoice)) {
if ((Type.SYSTEMGROUP.equals(structureElement.getType()) || Type.DISCIPLINE.equals(structureElement.getType()))
&& structureElement.getParent() != null) {
throw ExceptionUtil.createDataNotCorrectException(TextUtil.PARENT_IS_NOT_CORRECT, details, field);
} else if (StructureChoice.UPDATE.equals(structureChoice) || StructureChoice.DELETE.equals(structureChoice)) {
ValidateUtil.validateStructuresStatusSize0(
structureElement.getUuid(), structureElement.getType(), Status.PENDING, null,
holderRepositories, message, details, field);
......
This diff is collapsed.
This diff is collapsed.
......@@ -309,7 +309,7 @@ class ValidateUtilTest {
*/
@Test
void validateDataCreateName() {
ValidateUtil.validateNameDataCreate(null, null, null, null, null);
ValidateUtil.validateNameDataCreate(null, null, null, null);
}
/**
* Test of validate input update name element.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment