Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS will be completely phased out by mid-2025. To see alternatives please check here

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

Fix service group dialog change validation issue

parent 2fbe27c1
No related branches found
No related tags found
No related merge requests found
Showing
with 135 additions and 33 deletions
......@@ -69,8 +69,9 @@ export class DomainController implements SearchTableController {
}
isRecordChanged(oldModel, newModel): boolean {
for (var property in oldModel) {
const isEqual = this.isEqual(newModel[property],oldModel[property]);
for (let property in oldModel) {
let isEqual = this.isEqual(newModel[property],oldModel[property]);
//console.log("Property: "+property+" new: " +newModel[property] + "old: " +oldModel[property] + " val: " + isEqual );
if (!isEqual) {
return true; // Property has changed
}
......
......@@ -78,6 +78,8 @@ export class ServiceGroupDetailsDialogComponent implements OnInit {
this.current = this.editMode
? {
...this.data.row,
// copy serviceGroupDomain array
serviceGroupDomains: [...this.data.row.serviceGroupDomains]
}
: {
id: null,
......@@ -322,16 +324,19 @@ export class ServiceGroupDetailsDialogComponent implements OnInit {
// if deselected warn serviceMetadata will be deleted
let domainCode = event.option.value.domainCode;
if (!event.option.selected) {
this.dialog.open(ConfirmationDialogComponent, {
data: {
title: "Registered serviceMetadata on domain!",
description: "Unregistration of domain will also delete it's serviceMetadata. Do you want to continue?"
}
}).afterClosed().subscribe(result => {
if (!result) {
event.option.selected = true;
}
})
let smdCount = this.getServiceMetadataCountOnDomain(domainCode);
if (smdCount >0) {
this.dialog.open(ConfirmationDialogComponent, {
data: {
title: "Registered serviceMetadata on domain!",
description: "Unregistering service group from domain will also delete its serviceMetadata (count: "+smdCount+") from the domain! Do you want to continue?"
}
}).afterClosed().subscribe(result => {
if (!result) {
event.option.selected = true;
}
})
}
}
......
......@@ -97,17 +97,42 @@ export class ServiceGroupEditController implements SearchTableController {
// check if other properties were changed
let propSize = this.compareSGProperties.length;
for (let i = 0; i < propSize; i++) {
let property = this.compareSGProperties[i];
const isEqual = this.isEqual(newModel[property], oldModel[property]);
let isEqual = false;
if (property ==='users'
|| property ==='serviceGroupDomains') {
isEqual = this.isEqualListByAttribute(newModel[property], oldModel[property], "id");
}else {
isEqual = this.isEqual(newModel[property], oldModel[property]);
}
console.log("Property: "+property+" new: " +newModel[property] + "old: " +oldModel[property] + " val: " + isEqual );
if (!isEqual) {
console.log("property: "+property+" changed!");
return true; // Property has changed
}
}
return false;
}
isEqualListByAttribute(array1, array2, compareByAttribute): boolean {
let result1 = array1.filter(function(o1){
// filter out (!) items in result2
return !array2.some(function(o2){
return o1[compareByAttribute] === o2[compareByAttribute]; // unique id
});
});
let result2 = array2.filter(function(o1){
// filter out (!) items in result2
return !array1.some(function(o2){
return o1[compareByAttribute] === o2[compareByAttribute]; // unique id
});
});
return (!result1 || result1.length === 0) && (!result2 || result2.length === 0);
}
isEqual(val1, val2): boolean {
return (this.isEmpty(val1) && this.isEmpty(val2)
|| val1 === val2);
......
......@@ -132,8 +132,9 @@ export class ServiceGroupEditComponent implements OnInit {
formRef.afterClosed().subscribe(result => {
if (result) {
let isXMLChanged=formRef.componentInstance.isMetaDataXMLChanged();
if (!isXMLChanged){
// method isServiceMetaDataChanged must be called before getCurrent!
let isChanged=formRef.componentInstance.isServiceMetaDataChanged();
if (!isChanged ){
// nothing to save
return;
}
......@@ -182,15 +183,7 @@ export class ServiceGroupEditComponent implements OnInit {
}
}
isRecordChanged (oldModel, newModel): boolean {
for (var property in oldModel) {
var changed = false;
if (newModel[property] !== oldModel[property]) {
return true; // Property has changed
}
}
return false;
}
// for dirty guard...
isDirty (): boolean {
......
......@@ -260,11 +260,24 @@ export class ServiceGroupMetadataDialogComponent implements OnInit {
return this.current;
}
//!! this two method must be called before getCurrent
public isMetaDataXMLChanged():boolean{
return this.dialogForm.value['xmlContent'] !== this.current.xmlContent;
}
public isServiceMetaDataChanged():boolean{
return this.isMetaDataXMLChanged() || !this.isEqual(this.current.domainCode, this.domainList.selected.value.domainCode) ;
}
compareDomainCode(sgDomain: ServiceGroupDomainEditRo, domainCode: String): boolean {
return sgDomain.domainCode === domainCode;
}
isEqual(val1, val2): boolean {
return (this.isEmpty(val1) && this.isEmpty(val2)
|| val1 === val2);
}
isEmpty(str): boolean {
return (!str || 0 === str.length);
}
}
......@@ -123,9 +123,13 @@ public class DBServiceMetadata extends BaseEntity {
}
}
else {
smdx.setServiceMetadata(this);
if (this.serviceMetadataXml == null) {
this.serviceMetadataXml = new DBServiceMetadataXml();
this.serviceMetadataXml.setServiceMetadata(this);
}
this.serviceMetadataXml.setXmlContent(smdx.getXmlContent());
}
this.serviceMetadataXml = smdx;
}
@Transient
......
......@@ -352,23 +352,41 @@ public class UIServiceGroupService extends UIServiceBase<DBServiceGroup, Service
if (optionalDbServiceGroupDomain.isPresent()) {
DBServiceGroupDomain dbServiceGroupDomain = optionalDbServiceGroupDomain.get();
DBServiceMetadata dbServiceMetadata = dbServiceGroupDomain.getServiceMetadata(serviceMetadataRO.getDocumentIdentifier(),
serviceMetadataRO.getDocumentIdentifierScheme());
if (serviceMetadataRO.getXmlContentStatus() == EntityROStatus.UPDATED.getStatusNumber()) {
// get service metadata
byte[] buff = validateServiceMetadata(serviceMetadataRO);
DBServiceMetadata dbServiceMetadata = dbServiceGroupDomain.getServiceMetadata(serviceMetadataRO.getDocumentIdentifier(),
serviceMetadataRO.getDocumentIdentifierScheme());
dbServiceMetadata.setXmlContent(buff);
}
if (!Objects.equals(serviceMetadataRO.getDomainCode(), dbServiceGroupDomain.getDomain().getDomainCode())) {
// remove from old doman
// remove from old domain
LOG.info("Move service metadata from domain {} to domain: {}" , dbServiceGroupDomain.getDomain().getDomainCode(),
serviceMetadataRO.getDomainCode( ));
DBServiceMetadata smd = dbServiceGroupDomain.removeServiceMetadata(serviceMetadataRO.getDocumentIdentifier(),
serviceMetadataRO.getDocumentIdentifierScheme());
// find new domain and add
Optional<DBServiceGroupDomain> optNewDomain = dbServiceGroup.getServiceGroupForDomain(serviceMetadataRO.getDomainCode());
if (optNewDomain.isPresent()) {
optNewDomain.get().addServiceMetadata(smd);
LOG.info("ADD service metadata to domain {} " , optNewDomain.get().getDomain().getDomainCode(),
serviceMetadataRO.getDomainCode( ));
// create new because the old service metadata will be deleted
DBServiceMetadata smdNew = new DBServiceMetadata();
smdNew.setDocumentIdentifier(dbServiceMetadata.getDocumentIdentifier());
smdNew.setDocumentIdentifierScheme(dbServiceMetadata.getDocumentIdentifierScheme());
smdNew.setServiceGroupDomain(optNewDomain.get());
smdNew.setServiceMetadataXml(dbServiceMetadata.getServiceMetadataXml());
smdNew.setCreatedOn(dbServiceMetadata.getCreatedOn());
optNewDomain.get().addServiceMetadata(smdNew);
} else {
throw new SMPRuntimeException(SG_NOT_REGISTRED_FOR_DOMAIN, serviceMetadataRO.getDomainCode(),
serviceGroupRO.getParticipantIdentifier(), serviceGroupRO.getParticipantScheme());
......
......@@ -237,6 +237,49 @@ public class UIServiceGroupServiceIntegrationTest extends AbstractServiceIntegra
assertEquals(testDomain02.getSmlSubdomain(), smdUpdated.getSmlSubdomain());
}
@Test
public void testUpdateServiceMatadataChangeDomainReverseOrder() {
// given
DBDomain testDomain01 = TestDBUtils.createDBDomain(TestConstants.TEST_DOMAIN_CODE_1);
DBDomain testDomain02 = TestDBUtils.createDBDomain(TestConstants.TEST_DOMAIN_CODE_2);
domainDao.persistFlushDetach(testDomain02);
domainDao.persistFlushDetach(testDomain01);
DBServiceGroup dbServiceGroup = TestDBUtils.createDBServiceGroup();
dbServiceGroup.addDomain(testDomain02);
dbServiceGroup.addDomain(testDomain01);
DBServiceMetadata dbServiceMetadata = TestDBUtils.createDBServiceMetadata(dbServiceGroup.getParticipantIdentifier(), dbServiceGroup.getParticipantScheme());
dbServiceGroup.getServiceGroupDomains().get(1 ).addServiceMetadata(dbServiceMetadata);
// add second domain
serviceGroupDao.persistFlushDetach(dbServiceGroup);
ServiceResult<ServiceGroupRO> res = testInstance.getTableList(-1, -1, null, null, null);
assertNotNull(res);
assertEquals(1, res.getCount().intValue());
ServiceGroupRO sgChanged = res.getServiceEntities().get(0);
ServiceMetadataRO smdToChange = sgChanged.getServiceMetadata().get(0);
assertEquals(testDomain01.getDomainCode(), smdToChange.getDomainCode());
assertEquals(testDomain01.getSmlSubdomain(), smdToChange.getSmlSubdomain());
// then
sgChanged.setStatus(EntityROStatus.UPDATED.getStatusNumber());
smdToChange.setStatus(EntityROStatus.UPDATED.getStatusNumber());
smdToChange.setDomainCode(testDomain02.getDomainCode());
smdToChange.setSmlSubdomain(testDomain02.getSmlSubdomain());
testInstance.updateServiceGroupList(Collections.singletonList(sgChanged));
res = testInstance.getTableList(-1, -1, null, null, null);
ServiceGroupRO sgUpdated = res.getServiceEntities().get(0);
ServiceMetadataRO smdUpdated = sgUpdated.getServiceMetadata().get(0);
assertEquals(testDomain02.getDomainCode(), smdUpdated.getDomainCode());
assertEquals(testDomain02.getSmlSubdomain(), smdUpdated.getSmlSubdomain());
}
@Test
......
......@@ -119,7 +119,7 @@ public class ServiceGroupResource {
@RequestMapping(method = RequestMethod.PUT)
@Secured({SMPAuthority.S_AUTHORITY_TOKEN_SYSTEM_ADMIN, SMPAuthority.S_AUTHORITY_TOKEN_SMP_ADMIN, SMPAuthority.S_AUTHORITY_TOKEN_SERVICE_GROUP_ADMIN})
public void updateDomainList(@RequestBody(required = true) ServiceGroupRO[] updateEntities ){
LOG.info("GOT LIST OF ServiceGroupRO to UPDATE: " + updateEntities.length);
LOG.info("Update ServiceGroupRO count: " + updateEntities.length);
uiServiceGroupService.updateServiceGroupList(Arrays.asList(updateEntities));
}
......
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