Code development platform for open source projects from the European Union institutions

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

Fix duplicate resource and group creation

parent d3d49f74
No related branches found
No related tags found
No related merge requests found
Showing
with 29 additions and 17 deletions
......@@ -81,8 +81,11 @@
</table>
</div>
<mat-paginator [hidePageSize]="true"
<mat-paginator class="mat-elevation-z2" [length]="resultsLength"
[hidePageSize]="true"
[showFirstLastButtons]="true"
[pageSize]="5"
[disabled]="domainNotSelected"
aria-label="Select pages"></mat-paginator>
</div>
......
import {Component, Input, ViewChild,} from '@angular/core';
import {AfterViewInit, Component, Input, OnInit, ViewChild,} from '@angular/core';
import {FormBuilder} from "@angular/forms";
import {AlertMessageService} from "../../../common/alert-message/alert-message.service";
import {MatDialog} from "@angular/material/dialog";
......@@ -23,7 +23,7 @@ import {MemberTypeEnum} from "../../../common/enums/member-type.enum";
templateUrl: './domain-group.component.html',
styleUrls: ['./domain-group.component.scss']
})
export class DomainGroupComponent implements BeforeLeaveGuard {
export class DomainGroupComponent implements OnInit, AfterViewInit, BeforeLeaveGuard {
private _domain: DomainRo;
......@@ -55,6 +55,10 @@ export class DomainGroupComponent implements BeforeLeaveGuard {
};
}
ngAfterViewInit():void {
this.dataSource.paginator = this.paginator;
}
get domain(): DomainRo {
// no changes for the domain data
return this._domain;
......@@ -100,7 +104,9 @@ export class DomainGroupComponent implements BeforeLeaveGuard {
this.isLoadingResults = false;
}))
.subscribe((result: GroupRo[]) => {
this.dataSource.data = result;
this.resultsLength = result.length;
this.isLoadingResults = false;
}, (error) => {
this.alertService.error(error.error?.errorDescription)
......
......@@ -8,8 +8,6 @@ import {EditGroupService} from "./edit-group.service";
import {GroupRo} from "../../common/model/group-ro.model";
import {MemberTypeEnum} from "../../common/enums/member-type.enum";
import {ResourceDefinitionRo} from "../../system-settings/admin-extension/resource-definition-ro.model";
@Component({
moduleId: module.id,
templateUrl: './edit-group.component.html',
......@@ -18,8 +16,6 @@ import {ResourceDefinitionRo} from "../../system-settings/admin-extension/resour
export class EditGroupComponent implements OnInit, BeforeLeaveGuard {
@Output() onSelectedGroup: EventEmitter<GroupRo> = new EventEmitter<GroupRo>();
groupMembershipType: MemberTypeEnum = MemberTypeEnum.GROUP;
domainList: DomainRo[] = [];
groupList: GroupRo[] = [];
......
......@@ -16,6 +16,7 @@ package eu.europa.ec.edelivery.smp.data.dao;
import eu.europa.ec.edelivery.smp.data.enums.MembershipRoleType;
import eu.europa.ec.edelivery.smp.data.model.DBDomain;
import eu.europa.ec.edelivery.smp.data.model.DBGroup;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;
import javax.persistence.NoResultException;
......@@ -29,6 +30,8 @@ import java.util.Optional;
import static eu.europa.ec.edelivery.smp.data.dao.QueryNames.*;
import static eu.europa.ec.edelivery.smp.exceptions.ErrorCode.ILLEGAL_STATE_DOMAIN_GROUP_MULTIPLE_ENTRY;
import static eu.europa.ec.edelivery.smp.exceptions.ErrorCode.ILLEGAL_STATE_DOMAIN_MULTIPLE_ENTRY;
import static org.apache.commons.lang3.StringUtils.*;
import static org.apache.commons.lang3.StringUtils.lowerCase;
/**
* The group of resources with shared resource management rights. The user with group admin has rights to create/delete
......@@ -93,7 +96,7 @@ public class GroupDao extends BaseDao<DBGroup> {
public Optional<DBGroup> getGroupByNameAndDomain(String name, Long domainId) {
try {
TypedQuery<DBGroup> query = memEManager.createNamedQuery(QUERY_GROUP_BY_NAME_DOMAIN, DBGroup.class);
query.setParameter(PARAM_NAME, name);
query.setParameter(PARAM_NAME, lowerCase(trim(name)));
query.setParameter(PARAM_DOMAIN_ID, domainId);
return Optional.of(query.getSingleResult());
} catch (NoResultException e) {
......@@ -116,7 +119,7 @@ public class GroupDao extends BaseDao<DBGroup> {
public Optional<DBGroup> getGroupByNameAndDomainCode(String name, String domainCode) {
try {
TypedQuery<DBGroup> query = memEManager.createNamedQuery(QUERY_GROUP_BY_NAME_DOMAIN_CODE, DBGroup.class);
query.setParameter(PARAM_NAME, name);
query.setParameter(PARAM_NAME, lowerCase(trim(name)));
query.setParameter(PARAM_DOMAIN_CODE, domainCode);
return Optional.of(query.getSingleResult());
} catch (NoResultException e) {
......
......@@ -25,6 +25,9 @@ import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import static org.apache.commons.lang3.StringUtils.lowerCase;
import static org.apache.commons.lang3.StringUtils.trim;
/**
* Service bean provides only public group management methods.
*
......@@ -107,7 +110,7 @@ public class UIGroupPublicService extends UIServiceBase<DBGroup, GroupRO> {
DBDomain domain = domainDao.find(domainId);
DBGroup group = new DBGroup();
group.setGroupName(groupRO.getGroupName());
group.setGroupName(lowerCase(trim(groupRO.getGroupName())));
group.setGroupDescription(groupRO.getGroupDescription());
group.setVisibility(groupRO.getVisibility());
group.setDomain(domain);
......@@ -161,7 +164,7 @@ public class UIGroupPublicService extends UIServiceBase<DBGroup, GroupRO> {
throw new SMPRuntimeException(ErrorCode.INVALID_REQUEST, "UpdateGroup", "Group with does not exists!");
}
group.setGroupName(groupRO.getGroupName());
group.setGroupName(lowerCase(trim(groupRO.getGroupName())));
group.setGroupDescription(groupRO.getGroupDescription());
group.setVisibility(groupRO.getVisibility());
// to get ID for conversion
......
......@@ -185,13 +185,14 @@ public class UIResourceService {
if (!optDoredef.isPresent()) {
throw new SMPRuntimeException(ErrorCode.INVALID_REQUEST, ACTION_RESOURCE_CREATE, "Resource definition [" + resourceRO.getResourceTypeIdentifier() + "] is not registered for domain!");
}
Identifier resourceIdentifier = identifierService.normalizeParticipant(resourceRO.getIdentifierScheme(),
resourceRO.getIdentifierValue());
Optional<DBResource> existResource = resourceDao.getResource(resourceRO.getIdentifierValue(), resourceRO.getIdentifierScheme(), optRedef.get(), group.getDomain());
Optional<DBResource> existResource = resourceDao.getResource(resourceIdentifier.getValue(),resourceIdentifier.getScheme(), optRedef.get(), group.getDomain());
if (existResource.isPresent()) {
throw new SMPRuntimeException(ErrorCode.INVALID_REQUEST, ACTION_RESOURCE_CREATE, "Resource definition [val:" + resourceRO.getIdentifierValue() + " scheme:" + resourceRO.getIdentifierScheme() + "] already exists for domain!");
}
Identifier resourceIdentifier = identifierService.normalizeParticipant(resourceRO.getIdentifierScheme(),
resourceRO.getIdentifierValue());
DBResource resource = new DBResource();
resource.setIdentifierScheme(resourceIdentifier.getScheme());
......
......@@ -55,7 +55,7 @@ insert into SMP_DOMAIN_RESOURCE_DEF (ID, FK_RESOURCE_DEF_ID, FK_DOMAIN_ID,CREATE
(2, 2, 1, NOW(), NOW());
insert into SMP_GROUP (ID, FK_DOMAIN_ID, NAME, VISIBILITY, CREATED_ON, LAST_UPDATED_ON) values
(1, 1, 'Test group', 'PUBLIC', NOW(), NOW());
(1, 1, 'test group', 'PUBLIC', NOW(), NOW());
insert into SMP_GROUP_MEMBER (ID, FK_GROUP_ID, FK_USER_ID, MEMBERSHIP_ROLE, CREATED_ON, LAST_UPDATED_ON) values
(1, 1, 2, 'ADMIN', NOW(), NOW()),
......
......@@ -100,7 +100,7 @@ insert into SMP_DOMAIN (ID, DOMAIN_CODE, VISIBILITY, SML_SUBDOMAIN, SML_SMP_ID,
(1, 'testdomain','PUBLIC', 'test-domain', 'CEF-SMP-002','sample_key','sample_key',1,0, sysdate, sysdate);
insert into SMP_GROUP (ID, FK_DOMAIN_ID, NAME, VISIBILITY, CREATED_ON, LAST_UPDATED_ON) values
(1, 1, 'Test group', 'PUBLIC', sysdate, sysdate);
(1, 1, 'test group', 'PUBLIC', sysdate, sysdate);
insert into SMP_EXTENSION ( ID, IDENTIFIER, IMPLEMENTATION_NAME, NAME, VERSION, DESCRIPTION, CREATED_ON, LAST_UPDATED_ON) values
......
......@@ -9,7 +9,7 @@ insert into SMP_CREDENTIAL (ID, FK_USER_ID, CREDENTIAL_ACTIVE, CREDENTIAL_NAME,
insert into SMP_DOMAIN (ID, DOMAIN_CODE, VISIBILITY, SML_SUBDOMAIN, SML_SMP_ID, SIGNATURE_KEY_ALIAS, SML_CLIENT_KEY_ALIAS, SML_CLIENT_CERT_AUTH,SML_REGISTERED, CREATED_ON, LAST_UPDATED_ON) values
(1, 'testdomain','PUBLIC', 'test-domain', 'DOMI-SMP-001','sample_key','smp_domain_01',1,1, NOW(), NOW());
insert into SMP_GROUP (ID, FK_DOMAIN_ID, NAME, VISIBILITY, CREATED_ON, LAST_UPDATED_ON) values
(1, 1, 'Test group', 'PUBLIC', NOW(), NOW());
(1, 1, 'test group', 'PUBLIC', NOW(), NOW());
insert into SMP_EXTENSION ( ID, IDENTIFIER, IMPLEMENTATION_NAME, NAME, VERSION, DESCRIPTION, CREATED_ON, LAST_UPDATED_ON) values
(1, 'edelivery-oasis-smp-extension', 'OasisSMPExtension','Oasis SMP 1.0 and 2.0','1.0', 'Oasis SMP 1.0 and 2.0 extension', NOW(), NOW());
......
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