diff --git a/domismp-tests/domismp-docker/compose/domismp-tomcat-mysql/docker-compose.local.yml b/domismp-tests/domismp-docker/compose/domismp-tomcat-mysql/docker-compose.local.yml index 2f8c0a63b8ac7fb7edd6a958ca811001ceedba4e..c9d2740a0b50b59af06232cc6133c44e29fcb7f3 100644 --- a/domismp-tests/domismp-docker/compose/domismp-tomcat-mysql/docker-compose.local.yml +++ b/domismp-tests/domismp-docker/compose/domismp-tomcat-mysql/docker-compose.local.yml @@ -4,7 +4,7 @@ services: domismp-service: ports: -# - "3908:3306" + - "3908:3306" - "8982:8080" # - "6902:6901" # - "8953:53" diff --git a/domismp-tests/domismp-docker/images/domismp-tomcat-mysql/entrypoint.sh b/domismp-tests/domismp-docker/images/domismp-tomcat-mysql/entrypoint.sh index 3a519cea4cdb9c55f599341117e64117dea943dd..6f845c82d9b6ce5f2f073327fbaab308ba438dce 100755 --- a/domismp-tests/domismp-docker/images/domismp-tomcat-mysql/entrypoint.sh +++ b/domismp-tests/domismp-docker/images/domismp-tomcat-mysql/entrypoint.sh @@ -103,6 +103,8 @@ init_mysql() { sleep 3s mv /var/lib/mysql ${DATA_DIR} fi + # set mysql authentication plugin to mysql_native_password + printf "\n[mysqld]\nbind-address = 0.0.0.0\ndefault_authentication_plugin = mysql_native_password\n" | tee -a /etc/mysql/my.cnf rm -rf /var/lib/mysql ln -sf ${MYSQL_DATA_DIR} /var/lib/mysql @@ -119,7 +121,7 @@ init_mysql() { echo "[INFO] MySQL ${SMP_DB_SCHEMA} not found, creating initial DBs" echo 'Create smp database' - mysql -h localhost -u root -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '$MYSQL_ROOT_PASSWORD';drop schema if exists $SMP_DB_SCHEMA;DROP USER IF EXISTS $SMP_DB_USER; create schema $SMP_DB_SCHEMA;alter database $SMP_DB_SCHEMA charset=utf8; create user $SMP_DB_USER identified by '$SMP_DB_USER_PASSWORD';grant all on $SMP_DB_SCHEMA.* to $SMP_DB_USER;" + mysql -h localhost -u root -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '$MYSQL_ROOT_PASSWORD';CREATE USER 'root'@'%' IDENTIFIED BY '$MYSQL_ROOT_PASSWORD';GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';drop schema if exists $SMP_DB_SCHEMA;DROP USER IF EXISTS $SMP_DB_USER; create schema $SMP_DB_SCHEMA;alter database $SMP_DB_SCHEMA charset=utf8; create user $SMP_DB_USER identified by '$SMP_DB_USER_PASSWORD';grant all on $SMP_DB_SCHEMA.* to $SMP_DB_USER;" if [ -f "/tmp/custom-data/mysql5innodb.sql" ]; then echo "Use custom database script! " diff --git a/smp-angular/src/app/edit/edit-group/group-resource-panel/resource-dialog/resource-dialog.component.ts b/smp-angular/src/app/edit/edit-group/group-resource-panel/resource-dialog/resource-dialog.component.ts index 1c4d4153fb15e16be026dcae266d7ec863075996..0f0582066510150e871fcf645554f6960dbdb9c2 100644 --- a/smp-angular/src/app/edit/edit-group/group-resource-panel/resource-dialog/resource-dialog.component.ts +++ b/smp-angular/src/app/edit/edit-group/group-resource-panel/resource-dialog/resource-dialog.component.ts @@ -93,6 +93,7 @@ export class ResourceDialogComponent { resource.identifierScheme = this.resourceForm.get('identifierScheme').value; resource.resourceTypeIdentifier = this.resourceForm.get('resourceTypeIdentifier').value; resource.visibility = this.resourceForm.get('visibility').value; + resource.reviewEnabled = this.resourceForm.get('reviewEnabled').value; return resource; } @@ -156,16 +157,17 @@ export class ResourceDialogComponent { public createResource(resource: ResourceRo) { this.submitInProgress = true; - this.editGroupService.createResourceForGroup(this.resource, this.group, this.domain).subscribe((result: ResourceRo) => { - if (!!result) { - this.closeDialog(); + this.editGroupService.createResourceForGroup(this.resource, this.group, this.domain).subscribe({ + next: (result: ResourceRo) => { + if (!!result) { + this.closeDialog(); + } + this.submitInProgress = false; + }, error: (error) => { + this.alertService.error(error.error?.errorDescription) + this.submitInProgress = false; } - this.submitInProgress = false; - }, (error) => { - this.alertService.error(error.error?.errorDescription) - this.submitInProgress = false; }); - } public saveResource(resource: ResourceRo): void { diff --git a/smp-angular/src/app/edit/edit-resources/edit-resource.controller.ts b/smp-angular/src/app/edit/edit-resources/edit-resource.controller.ts index ec4e7f65f9d157ac3745be069a11ce36b2ed7e78..4cc6192e27b82fe489eb235a9471925e60cd4dad 100644 --- a/smp-angular/src/app/edit/edit-resources/edit-resource.controller.ts +++ b/smp-angular/src/app/edit/edit-resources/edit-resource.controller.ts @@ -3,11 +3,15 @@ import {GroupRo} from "../../common/model/group-ro.model"; import {ResourceRo} from "../../common/model/resource-ro.model"; import {TableResult} from "../../common/model/table-result.model"; import {DomainRo} from "../../common/model/domain-ro.model"; -import {ResourceDefinitionRo} from "../../system-settings/admin-extension/resource-definition-ro.model"; +import { + ResourceDefinitionRo +} from "../../system-settings/admin-extension/resource-definition-ro.model"; import {EditResourceService} from "./edit-resource.service"; import {EditDomainService} from "../edit-domain/edit-domain.service"; import {EditGroupService} from "../edit-group/edit-group.service"; -import {AlertMessageService} from "../../common/alert-message/alert-message.service"; +import { + AlertMessageService +} from "../../common/alert-message/alert-message.service"; import {MatTableDataSource} from "@angular/material/table"; /** @@ -18,7 +22,7 @@ import {MatTableDataSource} from "@angular/material/table"; * @since 5.1 */ @Injectable() -export class EditResourceController extends MatTableDataSource<ResourceRo>{ +export class EditResourceController extends MatTableDataSource<ResourceRo> { domainList: DomainRo[] = []; groupList: GroupRo[] = []; @@ -77,6 +81,20 @@ export class EditResourceController extends MatTableDataSource<ResourceRo>{ return this._selectedResource; }; + selectedResourceUpdated(resource: ResourceRo) { + // find current resource from list by resource id + if (resource.resourceId == this._selectedResource.resourceId) { + this._selectedResource.resourceTypeIdentifier = resource.resourceTypeIdentifier; + this._selectedResource.identifierScheme = resource.identifierScheme; + this._selectedResource.identifierValue = resource.identifierValue; + this._selectedResource.visibility = resource.visibility; + this._selectedResource.reviewEnabled = resource.reviewEnabled + } else { + console.log('selected resource not found') + this.selectedResource = resource; + } + } + @Input() set selectedResource(resource: ResourceRo) { this._selectedResource = resource; }; @@ -88,12 +106,14 @@ export class EditResourceController extends MatTableDataSource<ResourceRo>{ refreshDomains() { this.isLoadingResults = true; this.domainService.getDomainsForResourceAdminUserObservable() - .subscribe({next: (result: DomainRo[]) => { - this.updateDomainList(result) - }, error: (err: any) => { - this.alertService.error(err.error?.errorDescription) - this.isLoadingResults = false; - }}); + .subscribe({ + next: (result: DomainRo[]) => { + this.updateDomainList(result) + }, error: (err: any) => { + this.alertService.error(err.error?.errorDescription) + this.isLoadingResults = false; + } + }); } refreshGroups() { @@ -104,11 +124,13 @@ export class EditResourceController extends MatTableDataSource<ResourceRo>{ } this.isLoadingResults = true; this.groupService.getDomainGroupsForResourceAdminObservable(this.selectedDomain) - .subscribe((result: GroupRo[]) => { - this.updateGroupList(result) - }, (error: any) => { - this.isLoadingResults = false; - this.alertService.error(error.error?.errorDescription) + .subscribe({ + next: (result: GroupRo[]) => { + this.updateGroupList(result) + }, error: (error: any) => { + this.isLoadingResults = false; + this.alertService.error(error.error?.errorDescription) + } }); } @@ -121,21 +143,25 @@ export class EditResourceController extends MatTableDataSource<ResourceRo>{ this.isLoadingResults = true; this.resourceService.getGroupResourcesForResourceAdminObservable(this.selectedGroup, this.selectedDomain, this.resourcesFilter, this.pageIndex, this.pageSize) - .subscribe((result: TableResult<ResourceRo>) => { - this.updateResourceList(result.serviceEntities) - this.isLoadingResults = false; - }, (error: any) => { - this.isLoadingResults = false; - this.alertService.error(error.error?.errorDescription) + .subscribe({ + next: (result: TableResult<ResourceRo>) => { + this.updateResourceList(result.serviceEntities) + this.isLoadingResults = false; + }, error: (error: any) => { + this.isLoadingResults = false; + this.alertService.error(error.error?.errorDescription) + } }); } refreshDomainsResourceDefinitions() { this.domainService.getDomainResourceDefinitionsObservable(this.selectedDomain) - .subscribe((result: ResourceDefinitionRo[]) => { - this._selectedDomainResourceDefs = result - }, (error: any) => { - this.alertService.error(error.error?.errorDescription) + .subscribe({ + next: (result: ResourceDefinitionRo[]) => { + this._selectedDomainResourceDefs = result + }, error: (error: any) => { + this.alertService.error(error.error?.errorDescription) + } }); } @@ -158,20 +184,14 @@ export class EditResourceController extends MatTableDataSource<ResourceRo>{ } updateResourceList(list: ResourceRo[]) { - console.log('updateResourceList selected resource:' + this._selectedResource) - // find current resource from list by resource id - - let currR: ResourceRo = this.selectedResource; this.selectedResource = null; this.data = list; if (!!currR) { - console.log('selected resource :' + currR) this.selectedResource = list.find(r => r.identifierScheme == currR.identifierScheme && r.identifierValue == currR.identifierValue); - console.log('selected resource found :' + this._selectedResource) } if (!this.selectedResource && !!list && list.length > 0) { diff --git a/smp-angular/src/app/edit/edit-resources/resource-details-panel/resource-details-panel.component.ts b/smp-angular/src/app/edit/edit-resources/resource-details-panel/resource-details-panel.component.ts index 0329de97e2d1b94e2fd4e178365c61d26f24ecee..e99996e62e652ca2296eb736ebb392e4bbc3dd56 100644 --- a/smp-angular/src/app/edit/edit-resources/resource-details-panel/resource-details-panel.component.ts +++ b/smp-angular/src/app/edit/edit-resources/resource-details-panel/resource-details-panel.component.ts @@ -33,7 +33,6 @@ import {EditResourceController} from "../edit-resource.controller"; styleUrls: ['./resource-details-panel.component.scss'] }) export class ResourceDetailsPanelComponent implements BeforeLeaveGuard { - readonly groupVisibilityOptions = Object.keys(VisibilityEnum) .map(el => { return {key: el, value: VisibilityEnum[el]} @@ -157,8 +156,8 @@ export class ResourceDetailsPanelComponent implements BeforeLeaveGuard { try { if (!!result) { this.alertService.successForTranslation("resource.details.panel.alert.resource.saved"); - this.editResourceController.selectedResource = result; - this._resource = result; + this.editResourceController.selectedResourceUpdated(result); + this.resource = result; this.resourceForm.markAsPristine(); } } finally { diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ui/UIResourceService.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ui/UIResourceService.java index 0baf01917cd78ffa3a6552fc5e31a4d26cfdc61d..b37f4bfa94964cc5aef47bf171bb1942705aa254 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ui/UIResourceService.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ui/UIResourceService.java @@ -69,6 +69,8 @@ public class UIResourceService { private static final String ACTION_RESOURCE_UPDATE = "UpdateResource"; private static final SMPLogger LOG = SMPLoggerFactory.getLogger(UIResourceService.class); + public static final String GROUP_DOES_NOT_EXIST = "Group does not exist!"; + public static final String GROUP_DOES_NOT_BELONG_TO_THE_GIVEN_DOMAIN = "Group does not belong to the given domain!"; private final ResourceDao resourceDao; @@ -111,7 +113,7 @@ public class UIResourceService { DBGroup group = groupDao.find(groupId); if (group == null) { - throw new SMPRuntimeException(ErrorCode.INVALID_REQUEST, ACTION_RESOURCE_LIST, "Group does not exist!"); + throw new SMPRuntimeException(ErrorCode.INVALID_REQUEST, ACTION_RESOURCE_LIST, GROUP_DOES_NOT_EXIST); } DBResourceFilter filter = DBResourceFilter.createBuilder() @@ -142,7 +144,7 @@ public class UIResourceService { DBGroup group = groupDao.find(groupId); if (group == null) { - throw new SMPRuntimeException(ErrorCode.INVALID_REQUEST, ACTION_RESOURCE_LIST, "Group does not exist!"); + throw new SMPRuntimeException(ErrorCode.INVALID_REQUEST, ACTION_RESOURCE_LIST, GROUP_DOES_NOT_EXIST); } DBUser user = userDao.find(userId); if (user == null) { @@ -183,7 +185,7 @@ public class UIResourceService { throw new SMPRuntimeException(ErrorCode.INVALID_REQUEST, ACTION_RESOURCE_DELETE, "Resource does not belong to the group!"); } if (!Objects.equals(resource.getGroup().getDomain().getId(), domainId)) { - throw new SMPRuntimeException(ErrorCode.INVALID_REQUEST, ACTION_RESOURCE_DELETE, "Group does not belong to the given domain!"); + throw new SMPRuntimeException(ErrorCode.INVALID_REQUEST, ACTION_RESOURCE_DELETE, GROUP_DOES_NOT_BELONG_TO_THE_GIVEN_DOMAIN); } DBDomain resourceDomain = resource.getGroup().getDomain(); if (smlIntegrationService.isSMLIntegrationEnabled() && @@ -200,12 +202,12 @@ public class UIResourceService { DBGroup group = groupDao.find(groupId); if (group == null) { - throw new SMPRuntimeException(ErrorCode.INVALID_REQUEST, ACTION_RESOURCE_CREATE, "Group does not exist!"); + throw new SMPRuntimeException(ErrorCode.INVALID_REQUEST, ACTION_RESOURCE_CREATE, GROUP_DOES_NOT_EXIST); } DBDomain domain = group.getDomain(); if (!Objects.equals(domain.getId(), domainId)) { - throw new SMPRuntimeException(ErrorCode.INVALID_REQUEST, ACTION_RESOURCE_CREATE, "Group does not belong to the given domain!"); + throw new SMPRuntimeException(ErrorCode.INVALID_REQUEST, ACTION_RESOURCE_CREATE, GROUP_DOES_NOT_BELONG_TO_THE_GIVEN_DOMAIN); } Optional<DBResourceDef> optRedef = resourceDefDao.getResourceDefByIdentifier(resourceRO.getResourceTypeIdentifier()); @@ -270,11 +272,11 @@ public class UIResourceService { DBGroup group = groupDao.find(groupId); if (group == null) { - throw new SMPRuntimeException(ErrorCode.INVALID_REQUEST, ACTION_RESOURCE_UPDATE, "Group does not exist!"); + throw new SMPRuntimeException(ErrorCode.INVALID_REQUEST, ACTION_RESOURCE_UPDATE, GROUP_DOES_NOT_EXIST); } if (!Objects.equals(group.getDomain().getId(), domainId)) { - throw new SMPRuntimeException(ErrorCode.INVALID_REQUEST, ACTION_RESOURCE_UPDATE, "Group does not belong to the given domain!"); + throw new SMPRuntimeException(ErrorCode.INVALID_REQUEST, ACTION_RESOURCE_UPDATE, GROUP_DOES_NOT_BELONG_TO_THE_GIVEN_DOMAIN); } Optional<DBResourceDef> optRedef = resourceDefDao.getResourceDefByIdentifier(resourceRO.getResourceTypeIdentifier()); @@ -294,7 +296,12 @@ public class UIResourceService { if (resourceRO.isReviewEnabled() != null) { resource.setReviewEnabled(isTrue(resourceRO.isReviewEnabled())); } - return conversionService.convert(resource, ResourceRO.class); + ResourceRO resourceROResult = conversionService.convert(resource, ResourceRO.class); + if (StringUtils.isNotBlank(resourceRO.getResourceId())){ + // return the same encrypted id so the UI can use update old resource + resourceROResult.setResourceId(resourceRO.getResourceId()); + } + return resourceROResult; } @Transactional