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 7366f898 authored by Joze RIHTARSIC's avatar Joze RIHTARSIC
Browse files

- small bugfixes

parent 160a8b80
No related branches found
No related tags found
No related merge requests found
Showing
with 232 additions and 112 deletions
......@@ -26,32 +26,10 @@ export class AppComponent implements OnInit {
private securityEventService: SecurityEventService,
private http: HttpClient,
private titleService: Title) {
/*
let applicationNameResponse: Observable<string> = this.http.get<string>('rest/application/name');
applicationNameResponse.subscribe((name: string) => {
this.titleService.setTitle(name);
});
*/
}
ngOnInit() {
/*
this.securityEventService.onLoginSuccessEvent().subscribe(
data => {
this.isAdmin = this.securityService.isCurrentUserAdmin();
});
this.securityEventService.onLoginErrorEvent().subscribe(
error => {
this.isAdmin = this.securityService.isCurrentUserAdmin();
});
this.securityEventService.onLogoutSuccessEvent().subscribe(
data => {
this.isAdmin = this.securityService.isCurrentUserAdmin();
this.router.navigate(['/login']);
});*/
}
isCurrentUserSystemAdmin(): boolean {
......
......@@ -145,7 +145,7 @@ export class DomainDetailsDialogComponent {
'smlClientCertHeader': res.blueCoatHeader
});
} else {
this.alertService.exception("Error occurred while reading certificate.", "Check if uploaded file has valid certificate type?", false);
this.alertService.exception("Error occurred while reading certificate.", "Check if uploaded file has valid certificate type.", false);
}
},
err => {
......
......@@ -69,6 +69,8 @@ export class LoginComponent implements OnInit, OnDestroy {
break;
default:
message = "The username/password combination you provided are not valid. Please try again or contact your administrator.";
// clear the password
this.model.password='';
break;
}
break;
......@@ -85,6 +87,8 @@ export class LoginComponent implements OnInit, OnDestroy {
}
login() {
// clear alerts
this.alertService.clearAlert();
this.securityService.login(this.model.username, this.model.password);
}
......
......@@ -17,6 +17,11 @@
style="color:red; font-size: 70%">
Participant identifier must not be empty.
</div>
<div
*ngIf="(!editMode && dialogForm.controls['participantIdentifier'].hasError('dbExist'))"
style="color:red; font-size: 70%">
Participant identifier for given scheme is already defined in database!
</div>
</mat-form-field>
<mat-form-field style="width:100%">
......@@ -119,7 +124,7 @@
<span>Extension wizard</span>
</button>
<button mat-raised-button color="primary"
atTooltip="Validate extension by XSD schema."
atTooltip="Validate extension by XSD scheme."
matTooltipPosition="below"
(click)="onExtensionValidate()">
<mat-icon>warning</mat-icon>
......@@ -150,11 +155,7 @@
[style.color]="isExtensionValid?'green':'red'">
{{extensionValidationMessage}}
</div>
</div>
<!-- mat-form-field>
<div>
<textarea style="width:100% !important;height: 400px !important; -webkit-box-sizing: border-box;
......
......@@ -9,12 +9,13 @@ import {SearchTableEntityStatus} from "../../common/search-table/search-table-en
import {ServiceGroupEditRo} from "../service-group-edit-ro.model";
import {GlobalLookups} from "../../common/global-lookups";
import {ServiceGroupExtensionWizardDialogComponent} from "../service-group-extension-wizard-dialog/service-group-extension-wizard-dialog.component";
import {ServiceGroupExtensionRo} from "./service-extension-edit-ro.model";
import {ServiceGroupValidationRo} from "./service-group-validation-edit-ro.model";
import {DomainRo} from "../../domain/domain-ro.model";
import {ServiceGroupDomainEditRo} from "../service-group-domain-edit-ro.model";
import {ConfirmationDialogComponent} from "../../common/confirmation-dialog/confirmation-dialog.component";
import {SecurityService} from "../../security/security.service";
import {UserRo} from "../../user/user-ro.model";
import {ServiceGroupValidationErrorCodeModel} from "./service-group-validation-error-code.model";
@Component({
selector: 'service-group-details',
......@@ -34,7 +35,7 @@ export class ServiceGroupDetailsDialogComponent implements OnInit {
showSpinner: boolean = false;
dialogForm: FormGroup;
extensionObserver: Observable<ServiceGroupExtensionRo>;
extensionObserver: Observable<ServiceGroupValidationRo>;
extensionValidationMessage: String = null;
isExtensionValid: boolean = true;
......@@ -90,7 +91,7 @@ export class ServiceGroupDetailsDialogComponent implements OnInit {
this.current.status !== SearchTableEntityStatus.NEW ? Validators.required : null),
'serviceGroupDomains': new FormControl({value: []}, [this.minSelectedListCount(1)]),
'users': new FormControl({value: []}, [this.minSelectedListCount(1)]),
'extension': new FormControl({value: []}, []),
'extension': new FormControl({value: ''}, []),
});
......@@ -107,8 +108,8 @@ export class ServiceGroupDetailsDialogComponent implements OnInit {
// retrieve xml extension for this service group
if (this.current.status !== SearchTableEntityStatus.NEW && !this.current.extension) {
// init domains
this.extensionObserver = this.http.get<ServiceGroupExtensionRo>(SmpConstants.REST_SERVICE_GROUP_EXTENSION + '/' + this.current.id);
this.extensionObserver.subscribe((res: ServiceGroupExtensionRo) => {
this.extensionObserver = this.http.get<ServiceGroupValidationRo>(SmpConstants.REST_SERVICE_GROUP_EXTENSION + '/' + this.current.id);
this.extensionObserver.subscribe((res: ServiceGroupValidationRo) => {
this.dialogForm.get('extension').setValue(res.extension);
});
}
......@@ -125,18 +126,26 @@ export class ServiceGroupDetailsDialogComponent implements OnInit {
this.checkValidity(this.dialogForm);
let request: ServiceGroupExtensionRo = {
let request: ServiceGroupValidationRo = {
serviceGroupId: this.current.id,
participantScheme: this.dialogForm.controls['participantScheme'].value,
participantIdentifier: this.dialogForm.controls['participantIdentifier'].value,
extension: this.dialogForm.controls['extension'].value,
statusAction: this.editMode?SearchTableEntityStatus.UPDATED:SearchTableEntityStatus.NEW,
}
//
let validationObservable = this.http.post<ServiceGroupExtensionRo>(SmpConstants.REST_SERVICE_GROUP_EXTENSION_VALIDATE, request);
let validationObservable = this.http.post<ServiceGroupValidationRo>(SmpConstants.REST_SERVICE_GROUP_EXTENSION_VALIDATE, request);
this.showSpinner = true;
validationObservable.toPromise().then((res: ServiceGroupExtensionRo) => {
validationObservable.toPromise().then((res: ServiceGroupValidationRo) => {
if (res.errorMessage) {
this.extensionValidationMessage = res.errorMessage;
this.isExtensionValid = false;
this.showSpinner = false;
if (res.errorCode == ServiceGroupValidationErrorCodeModel.ERROR_CODE_SERVICE_GROUP_EXISTS){
this.dialogForm.controls['participantIdentifier'].setErrors({'dbExist': true});
} else {
this.extensionValidationMessage = res.errorMessage;
}
} else {
this.extensionValidationMessage = "Extension is valid!";
this.isExtensionValid = true;
......@@ -237,14 +246,17 @@ export class ServiceGroupDetailsDialogComponent implements OnInit {
public onExtensionValidate() {
let request: ServiceGroupExtensionRo = {
let request: ServiceGroupValidationRo = {
serviceGroupId: this.current.id,
participantScheme: this.dialogForm.controls['participantScheme'].value,
participantIdentifier: this.dialogForm.controls['participantIdentifier'].value,
extension: this.dialogForm.controls['extension'].value,
statusAction: SearchTableEntityStatus.UPDATED, // do not validate as new - for new participant id and schema is also validated
}
//
let validationObservable = this.http.post<ServiceGroupExtensionRo>(SmpConstants.REST_SERVICE_GROUP_EXTENSION_VALIDATE, request);
let validationObservable = this.http.post<ServiceGroupValidationRo>(SmpConstants.REST_SERVICE_GROUP_EXTENSION_VALIDATE, request);
this.showSpinner = true;
validationObservable.toPromise().then((res: ServiceGroupExtensionRo) => {
validationObservable.toPromise().then((res: ServiceGroupValidationRo) => {
if (res.errorMessage) {
this.extensionValidationMessage = res.errorMessage;
this.isExtensionValid = false;
......@@ -259,22 +271,7 @@ export class ServiceGroupDetailsDialogComponent implements OnInit {
}
onPrettyPrintExtension() {
let existingXML = this.dialogForm.controls['extension'].value;
let request: ServiceGroupExtensionRo = {
serviceGroupId: this.current.id,
extension: existingXML,
}
let validationObservable = this.http.post<ServiceGroupExtensionRo>(SmpConstants.REST_SERVICE_GROUP_EXTENSION_FORMAT, request);
validationObservable.subscribe((res: ServiceGroupExtensionRo) => {
if (res.errorMessage) {
this.extensionValidationMessage = res.errorMessage;
this.isExtensionValid = false;
} else {
this.dialogForm.get('extension').setValue(res.extension);
this.isExtensionValid = true;
}
});
}
onDomainSelectionChanged(event) {
......
export interface ServiceGroupExtensionRo {
export interface ServiceGroupValidationRo {
serviceGroupId: number;
participantScheme: string;
participantIdentifier: string;
extension: string;
errorMessage?: string;
statusAction:number;
errorCode?: number;
}
export enum ServiceGroupValidationErrorCodeModel {
ERROR_CODE_OK,
ERROR_CODE_SERVICE_GROUP_EXISTS,
ERROR_CODE_INVALID_EXTENSION
}
......@@ -6,7 +6,7 @@
<mat-card-content >
<div class="panel">
<mat-form-field style="width:30%">
<input matInput placeholder="Participant schema" name="patricipantSchema" id="participanSchema_id"
<input matInput placeholder="Participant scheme" name="patricipantSchema" id="participanSchema_id"
[formControl]="dialogForm.controls['participantScheme']"
>
</mat-form-field>
......@@ -28,11 +28,11 @@
<mat-form-field style="width:30%">
<input matInput placeholder="Document identifier scheme" name="documentScheme" id="documentScheme_id"
[formControl]="dialogForm.controls['documentIdentifierScheme']">
[formControl]="dialogForm.controls['documentIdentifierScheme']" maxlength="255" required>
</mat-form-field>
<mat-form-field style="width:55%">
<input matInput placeholder="Document identifier" name="documentIdentifier" id="documentIdentifier_id"
[formControl]="dialogForm.controls['documentIdentifier']">
[formControl]="dialogForm.controls['documentIdentifier']" maxlength="255" required>
</mat-form-field>
</div>
</mat-card-content>
......@@ -74,37 +74,29 @@
</mat-toolbar-row>
</mat-toolbar>
<div style="display: block;" style="border:1px; solid: #999999;margin:5px 0; padding:3px;">
<div style="display: block;border:1px; solid: #999999;margin:5px 0; padding:3px;">
<div class="textwrapper">
<textarea matInput style="width:100%;border: #03A9F4 1px solid" cols="2" rows="25"
resizeable="false"
id="MetadataTextArea"
placeholder="Metadata XML" name="metadataXML"
placeholder="Metadata XML*" name="metadataXML"
[formControl]="dialogForm.controls['xmlContent']"
></textarea>
required></textarea>
</div>
<div
*ngIf="metadataValidationMessage"
*ngIf="(!editMode && dialogForm.controls['xmlContent'].dirty || editMode) && dialogForm.controls['xmlContent'].hasError('required')"
style="color:red; font-size: 70%">
Valid service metadata XML is required!
</div>
<div
*ngIf="metadataValidationMessage && !((!editMode && dialogForm.controls['xmlContent'].touched || editMode) && dialogForm.controls['xmlContent'].hasError('required'))"
[style.color]="isMetadataValid?'green':'red'">
{{metadataValidationMessage}}
</div>
</div>
<!-- mat-form-field>
<div>
<textarea style="width:100% !important;height: 400px !important; -webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;"
matInput id="extensionTextArea"
placeholder="Extension" name="extension"
[formControl]="dialogForm.controls['extension']"
></textarea>
</div>
</mat-form-field -->
</mat-card-content>
</mat-card>
</div>
......
......@@ -73,7 +73,7 @@ export class ServiceGroupMetadataDialogComponent implements OnInit {
disabled: this.editMode
},
[Validators.required]),
'xmlContent': new FormControl({value: []}, []),
'xmlContent': new FormControl({value: ''}, [Validators.required]),
});
// update values
......@@ -123,6 +123,7 @@ export class ServiceGroupMetadataDialogComponent implements OnInit {
documentIdentifierScheme: this.dialogForm.controls['documentIdentifierScheme'].value,
documentIdentifier: this.dialogForm.controls['documentIdentifier'].value,
xmlContent: this.dialogForm.controls['xmlContent'].value,
statusAction: this.editMode?SearchTableEntityStatus.UPDATED:SearchTableEntityStatus.NEW,
}
//
let validationObservable = this.http.post<ServiceMetadataValidationEditRo>(SmpConstants.REST_METADATA_VALIDATE, request);
......@@ -191,11 +192,13 @@ export class ServiceGroupMetadataDialogComponent implements OnInit {
onServiceMetadataValidate() {
let request: ServiceMetadataValidationEditRo = {
participantScheme: this.dialogForm.controls['participantScheme'].value,
participantIdentifier: this.dialogForm.controls['participantIdentifier'].value,
documentIdentifierScheme: this.dialogForm.controls['documentIdentifierScheme'].value,
documentIdentifier: this.dialogForm.controls['documentIdentifier'].value,
xmlContent: this.dialogForm.controls['xmlContent'].value,
statusAction: this.editMode?SearchTableEntityStatus.UPDATED:SearchTableEntityStatus.NEW,
}
//
let validationObservable = this.http.post<ServiceMetadataValidationEditRo>(SmpConstants.REST_METADATA_VALIDATE, request);
......
......@@ -7,4 +7,5 @@ export interface ServiceMetadataValidationEditRo {
errorMessage?: string;
xmlContent?: string;
statusAction: number;
}
......@@ -7,7 +7,7 @@
<div class="panel">
<!-- Participant -->
<mat-form-field style="width:35%">
<input matInput placeholder="Participant identifier schema" name="participantIdentifierScheme"
<input matInput placeholder="Participant identifier scheme" name="participantIdentifierScheme"
id="participantIdentifierScheme_id" maxlength="255">
</mat-form-field>
<mat-form-field style="width:60%">
......@@ -21,7 +21,7 @@
</mat-form-field>
<!-- Document -->
<mat-form-field style="width:35%">
<input matInput placeholder="Document identifier schema" name="documentIdentifierScheme"
<input matInput placeholder="Document identifier scheme" name="documentIdentifierScheme"
id="documentIdentifierScheme_id"
maxlength="255">
</mat-form-field>
......@@ -32,7 +32,7 @@
</mat-form-field>
<!-- Process -->
<mat-form-field style="width:35%">
<input matInput placeholder="Process schema" name="processSchema" id="processSchema_id"
<input matInput placeholder="Process scheme" name="processSchema" id="processSchema_id"
maxlength="255" required>
</mat-form-field>
......
......@@ -35,7 +35,7 @@ export class ServiceMetadataWizardDialogComponent {
'documentIdentifier': new FormControl({value: ''}, [Validators.required]),
'documentIdentifierScheme': new FormControl({value: ''}, null),
'processSchema': new FormControl({value: ''}, [Validators.required]),
'processScheme': new FormControl({value: ''}, [Validators.required]),
'processIdentifier': new FormControl({value: ''}, [Validators.required]),
'endpointUrl': new FormControl({value: ''}, [Validators.required]),
'endpointCertificate': new FormControl({value: ''}, null),
......
......@@ -4,7 +4,7 @@ export interface ServiceMetadataWizardRo {
participantIdentifier: string;
documentIdentifierScheme: string;
documentIdentifier: string;
processSchema: string;
processScheme: string;
processIdentifier: string;
transportProfile: string;
endpointUrl: string;
......
......@@ -103,11 +103,11 @@
</mat-slide-toggle>
<div
*ngIf="userForm.errors?.userDetailsOrCertificateRequired && (userForm.get('userToggle').dirty || userForm.get('certificateToggle').dirty)"
class="has-error">You need to enter at least the details or the certificate for this user
</div>
<div *ngIf="userForm.errors?.certificateDetailsRequired && userForm.get('certificateToggle').touched"
class="has-error">All the certificate fields are required so please upload a new certificate
</div>
class="has-error">You need to enter at least the details or the certificate for this user!</div>
<div *ngIf="userForm.errors?.certificatedetailsrequired && userForm.get('certificateToggle').touched"
class="has-error">All the certificate fields are required so please upload a new certificate!</div>
<div *ngIf="userForm.errors?.certificateIdExists"
class="has-error">Certificate is already used by another user!</div>
</mat-card-title>
<mat-card-content>
<div class="panel">
......@@ -129,7 +129,8 @@
</mat-form-field>
<mat-form-field style="width: 100%;">
<input matInput placeholder="SMP certificate ID" [formControl]="userForm.controls['certificateId']"
id="certificateId_id">
id="certificateId_id"
resizeable="true">
</mat-form-field>
<label class="custom-file-upload">
......
......@@ -74,9 +74,19 @@ export class UserDetailsDialogComponent {
&& certificateToggle.value && !(subject.value && validFrom.value && validTo.value && issuer.value && serialNumber.value) ? { certificateDetailsRequired: true} : null;
};
private certificateExistValidator: ValidatorFn = (control: FormGroup): ValidationErrors | null => {
const certificateToggle = control.get('certificateToggle');
const certificateId = control.get('certificateId');
// get all persisted
const listIds = this.lookups.cachedServiceGroupOwnerList.map(a => a.certificate?a.certificate.certificateId:"NoId");
return certificateToggle && certificateId && certificateId.value
&& listIds.includes(certificateId.value) && this.current.certificate && certificateId.value !== this.current.certificate.certificateId ? { certificateIdExists: true} : null;
};
notInList(list: string[]) {
return (c: AbstractControl): { [key: string]: any } => {
if (c.value && list.includes(c.value))
if (c.value && list.includes(c.value.toString().toLowerCase()))
return {'notInList': {valid: false}};
return null;
......@@ -132,8 +142,8 @@ export class UserDetailsDialogComponent {
'passwordToggle': new FormControl({value: bSetPassword, disabled:!bUserPasswordAuthentication}),
'username': new FormControl({ value: '', disabled: this.editMode || !bUserPasswordAuthentication },
!this.editMode || !this.current.username ? [Validators.nullValidator, Validators.pattern(this.usernamePattern),
this.notInList(this.lookups.cachedServiceGroupOwnerList.map(a => a.username))] : null),
// improve notInList validator
this.notInList(this.lookups.cachedServiceGroupOwnerList.map(a => a.username?a.username.toLowerCase():null))] : null),
// // improve notInList validator
'password': new FormControl({ value: '', disabled: !bUserPasswordAuthentication || !bSetPassword},
[Validators.required, Validators.pattern(this.passwordPattern)]),
'confirmation': new FormControl({ value: '', disabled: !bUserPasswordAuthentication || !bSetPassword},
......@@ -145,9 +155,14 @@ export class UserDetailsDialogComponent {
'validTo': new FormControl({ value: '', disabled: true }, Validators.required),
'issuer': new FormControl({ value: '', disabled: true }, Validators.required),
'serialNumber': new FormControl({ value: '', disabled: true }, Validators.required),
'certificateId': new FormControl({ value: '', disabled: true }, Validators.required),
'certificateId': new FormControl({ value: '', disabled: true, }, [Validators.required]
),
}, {
validator: [this.passwordConfirmationValidator, this.atLeastOneToggleCheckedValidator, this.certificateValidator]
validator: [this.passwordConfirmationValidator,
this.atLeastOneToggleCheckedValidator,
this.certificateValidator,
this.certificateExistValidator,
]
});
// bind values to form! not property
this.userForm.controls['active'].setValue(this.current.active);
......@@ -205,7 +220,7 @@ export class UserDetailsDialogComponent {
'certificateId': res.certificateId
});
} else {
this.alertService.exception("Error occurred while reading certificate.", "Check if uploaded file has valid certificate type?", false);
this.alertService.exception("Error occurred while reading certificate.", "Check if uploaded file has valid certificate type.", false);
}
},
err => {
......
......@@ -39,7 +39,7 @@ public class UserDao extends BaseDao<DBUser> {
/**
* Perstis user to database. Before that test if user has identifiers
* Persis user to database. Before that test if user has identifiers. Usernames are saved to database in lower caps
* @param user
*/
@Override
......@@ -49,6 +49,10 @@ public class UserDao extends BaseDao<DBUser> {
&& (user.getCertificate() == null || StringUtils.isBlank(user.getCertificate().getCertificateId() )) ) {
throw new SMPRuntimeException(ErrorCode.INVALID_USER_NO_IDENTIFIERS);
}
// update username to lower caps
if (!StringUtils.isBlank(user.getUsername())){
user.setUsername(user.getUsername().toLowerCase());
}
super.persistFlushDetach(user);
}
......
package eu.europa.ec.edelivery.smp.data.ui;
public class ServiceGroupExtensionRO extends BaseRO {
public class ServiceGroupValidationRO extends BaseRO {
private static final long serialVersionUID = -7555221767041516157L;
public static int ERROR_CODE_OK =0;
public static int ERROR_CODE_SERVICE_GROUP_EXISTS =1;
public static int ERROR_CODE_INVALID_EXTENSION =2;
Long serviceGroupId;
String extension;
String errorMessage;
String participantScheme;
String participantIdentifier;
int statusAction = 0;
int errorCode = ERROR_CODE_OK;
public Long getServiceGroupId() {
return serviceGroupId;
......@@ -29,4 +39,36 @@ public class ServiceGroupExtensionRO extends BaseRO {
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
public int getStatusAction() {
return statusAction;
}
public void setStatusAction(int statusAction) {
this.statusAction = statusAction;
}
public String getParticipantScheme() {
return participantScheme;
}
public void setParticipantScheme(String participantScheme) {
this.participantScheme = participantScheme;
}
public String getParticipantIdentifier() {
return participantIdentifier;
}
public void setParticipantIdentifier(String participantIdentifier) {
this.participantIdentifier = participantIdentifier;
}
public int getErrorCode() {
return errorCode;
}
public void setErrorCode(int errorCode) {
this.errorCode = errorCode;
}
}
......@@ -17,6 +17,8 @@ public class ServiceMetadataValidationRO extends BaseRO {
String errorMessage;
String xmlContent;
int statusAction = 0;
public String getParticipantScheme() {
return participantScheme;
}
......@@ -64,4 +66,12 @@ public class ServiceMetadataValidationRO extends BaseRO {
public void setXmlContent(String xmlContent) {
this.xmlContent = xmlContent;
}
public int getStatusAction() {
return statusAction;
}
public void setStatusAction(int statusAction) {
this.statusAction = statusAction;
}
}
\ No newline at end of file
......@@ -27,8 +27,8 @@ public enum SMPMessageCode implements MessageCode {
BUS_HTTP_GET_SERVICE_METADATA ("BUS-012", "Http GET ServiceGroup from host: {}, ServiceGroup id: {}, metadata id {}."),
BUS_HTTP_GET_END_SERVICE_METADATA ("BUS-013", "End Http GET ServiceGroup from host: {}, ServiceGroup id: {}, metadata id {}."),
BUS_SAVE_SERVICE_GROUP ("BUS-014", "Start inserting/updating ServiceGroup for domain {}, part. Id: {} part. schema {}."),
BUS_SAVE_SERVICE_GROUP_FAILED ("BUS-015", "Inserting/updating ServiceGroup for domain {}, part. Id: {} part. schema {} failed! Error: [{}]"),
BUS_SAVE_SERVICE_GROUP ("BUS-014", "Start inserting/updating ServiceGroup for domain {}, part. Id: {} part. scheme {}."),
BUS_SAVE_SERVICE_GROUP_FAILED ("BUS-015", "Inserting/updating ServiceGroup for domain {}, part. Id: {} part. scheme {} failed! Error: [{}]"),
BUS_INVALID_XML("BUS-030", "Invalid XML for {}. Error: [{}]"),
......
......@@ -36,6 +36,9 @@ import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import static eu.europa.ec.edelivery.smp.data.ui.ServiceGroupValidationRO.ERROR_CODE_INVALID_EXTENSION;
import static eu.europa.ec.edelivery.smp.data.ui.ServiceGroupValidationRO.ERROR_CODE_OK;
import static eu.europa.ec.edelivery.smp.data.ui.ServiceGroupValidationRO.ERROR_CODE_SERVICE_GROUP_EXISTS;
import static eu.europa.ec.edelivery.smp.exceptions.ErrorCode.*;
@Service
......@@ -109,8 +112,8 @@ public class UIServiceGroupService extends UIServiceBase<DBServiceGroup, Service
}
@Transactional
public ServiceGroupExtensionRO getServiceGroupExtensionById(Long serviceGroupId) {
ServiceGroupExtensionRO ex = new ServiceGroupExtensionRO();
public ServiceGroupValidationRO getServiceGroupExtensionById(Long serviceGroupId) {
ServiceGroupValidationRO ex = new ServiceGroupValidationRO();
DBServiceGroup dbServiceGroup = getDatabaseDao().find(serviceGroupId);
ex.setServiceGroupId(dbServiceGroup.getId());
if (dbServiceGroup.getExtension() != null) {
......@@ -493,8 +496,9 @@ public class UIServiceGroupService extends UIServiceBase<DBServiceGroup, Service
byte[] buff = validateServiceMetadata(serviceMetadataRO);
DBServiceMetadata dbServiceMetadata = new DBServiceMetadata();
dbServiceMetadata.setDocumentIdentifier(serviceMetadataRO.getDocumentIdentifier());
dbServiceMetadata.setDocumentIdentifierScheme(serviceMetadataRO.getDocumentIdentifierScheme());
DocumentIdentifier docIdent= caseSensitivityNormalizer.normalizeDocumentIdentifier(serviceMetadataRO.getDocumentIdentifierScheme(),serviceMetadataRO.getDocumentIdentifier() );
dbServiceMetadata.setDocumentIdentifier(docIdent.getValue());
dbServiceMetadata.setDocumentIdentifierScheme(docIdent.getScheme());
dbServiceMetadata.setXmlContent(buff);
return dbServiceMetadata;
......@@ -525,26 +529,47 @@ public class UIServiceGroupService extends UIServiceBase<DBServiceGroup, Service
/**
* Validate if extension is valid by schema.
*
* @param sgExtension
* @param serviceGroup
* @return
*/
public ServiceGroupExtensionRO validateExtension(ServiceGroupExtensionRO sgExtension) {
if (sgExtension == null) {
public ServiceGroupValidationRO validateServiceGroup(ServiceGroupValidationRO serviceGroup) {
if (serviceGroup == null) {
throw new SMPRuntimeException(INVALID_REQEUST, "Validate extension", "Missing Extension parameter");
} else if (StringUtils.isBlank(sgExtension.getExtension())) {
sgExtension.setErrorMessage("Empty extension");
} // if new check if service group already exist
if (serviceGroup.getStatusAction() == EntityROStatus.NEW.getStatusNumber()){
ParticipantIdentifierType headerPI = caseSensitivityNormalizer.normalizeParticipantIdentifier(
serviceGroup.getParticipantScheme(),
serviceGroup.getParticipantIdentifier());
Optional<DBServiceGroup> sg= serviceGroupDao.findServiceGroup(serviceGroup.getParticipantIdentifier(),
serviceGroup.getParticipantScheme());
if (sg.isPresent()) {
serviceGroup.setErrorMessage("Service group: " +serviceGroup.getParticipantScheme()+ ":"+serviceGroup.getParticipantIdentifier()+
" already exists!");
serviceGroup.setErrorCode(ERROR_CODE_SERVICE_GROUP_EXISTS);
return serviceGroup;
}
}
if (StringUtils.isBlank(serviceGroup.getExtension())) {
// emtpy extension is also a valid extension;
serviceGroup.setErrorMessage(null);
} else {
try {
byte[] buff = sgExtension.getExtension().getBytes("UTF-8");
byte[] buff = serviceGroup.getExtension().getBytes("UTF-8");
ExtensionConverter.validateExtensionBySchema(buff); // validate by schema
sgExtension.setErrorMessage(null);
serviceGroup.setErrorMessage(null);
serviceGroup.setErrorCode(ERROR_CODE_OK);
} catch (XmlInvalidAgainstSchemaException e) {
sgExtension.setErrorMessage(ExceptionUtils.getRootCauseMessage(e));
serviceGroup.setErrorMessage(ExceptionUtils.getRootCauseMessage(e));
serviceGroup.setErrorCode(ERROR_CODE_INVALID_EXTENSION);
} catch (UnsupportedEncodingException e) {
sgExtension.setErrorMessage(ExceptionUtils.getRootCauseMessage(e));
serviceGroup.setErrorMessage(ExceptionUtils.getRootCauseMessage(e));
serviceGroup.setErrorCode(ERROR_CODE_INVALID_EXTENSION);
}
}
return sgExtension;
return serviceGroup;
}
/**
......@@ -568,12 +593,12 @@ public class UIServiceGroupService extends UIServiceBase<DBServiceGroup, Service
}
/**
* TODO format extension - add root element and format...
* Method
*
* @param sgExtension
* @return
*/
public ServiceGroupExtensionRO formatExtension(ServiceGroupExtensionRO sgExtension) {
public ServiceGroupValidationRO formatExtension(ServiceGroupValidationRO sgExtension) {
if (sgExtension == null) {
throw new SMPRuntimeException(INVALID_REQEUST, "Format extension", "Missing Extension parameter");
} else if (StringUtils.isBlank(sgExtension.getExtension())) {
......
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