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

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

Fix subresource save with the same identifiers

parent f91c8396
No related branches found
No related tags found
No related merge requests found
......@@ -10,9 +10,6 @@ import {ResourceDefinitionRo} from "../../../../system-settings/admin-extension/
import {EditGroupService} from "../../../edit-group/edit-group.service";
import {SubresourceRo} from "../../../../common/model/subresource-ro.model";
import {EditResourceService} from "../../edit-resource.service";
@Component({
templateUrl: './subresource-dialog.component.html',
styleUrls: ['./subresource-dialog.component.css']
......@@ -56,8 +53,8 @@ export class SubresourceDialogComponent {
get subresource(): SubresourceRo {
let entity = {...this._subresource};
entity.identifierScheme = this.resourceForm.get('identifierValue').value;
entity.identifierValue = this.resourceForm.get('identifierScheme').value;
entity.identifierScheme = this.resourceForm.get('identifierScheme').value;
entity.identifierValue = this.resourceForm.get('identifierValue').value;
entity.subresourceTypeIdentifier = this.resourceForm.get('subresourceTypeIdentifier').value;
return entity;
}
......
......@@ -46,7 +46,8 @@ import static eu.europa.ec.edelivery.smp.data.dao.QueryNames.*;
@NamedQuery(name = QUERY_SUBRESOURCE_BY_IDENTIFIER_RESOURCE_ID , query = "SELECT d FROM DBSubresource d WHERE d.resource.id = :resource_id " +
" AND d.identifierValue=:subresource_identifier " +
" AND d.identifierScheme=:subresource_scheme"
" AND (:subresource_scheme IS NULL AND d.identifierScheme IS NULL " +
" OR d.identifierScheme = :subresource_scheme)"
)
@NamedQuery(name = QUERY_SUBRESOURCE_BY_RESOURCE_ID , query = "SELECT d FROM DBSubresource d WHERE d.resource.id = :resource_id order by id asc")
......
......@@ -93,24 +93,22 @@ public class UISubresourceService {
if (!optRedef.isPresent()) {
throw new SMPRuntimeException(ErrorCode.INVALID_REQUEST, ACTION_SUBRESOURCE_CREATE, "Subresource definition [" + subResourceRO.getSubresourceTypeIdentifier() + "] does not exist!");
}
Identifier docId = identifierService.normalizeDocument(subResourceRO.getIdentifierScheme(), subResourceRO.getIdentifierValue());
Identifier docId = identifierService.normalizeDocument(subResourceRO.getIdentifierScheme(),
subResourceRO.getIdentifierValue());
Optional<DBSubresource> exists= subresourceDao.getSubResourcesForResource(docId, resParent);
if (exists.isPresent()) {
throw new SMPRuntimeException(ErrorCode.INVALID_REQUEST, ACTION_SUBRESOURCE_CREATE, "Subresource definition [val:" + docId.getValue() + " scheme:" + docId.getScheme() + "] already exists for the resource!");
}
DBSubresource subresource = new DBSubresource();
subresource.setIdentifierScheme(docId.getValue());
subresource.setIdentifierValue(docId.getScheme());
subresource.setIdentifierScheme(docId.getScheme());
subresource.setIdentifierValue(docId.getValue());
subresource.setResource(resParent);
subresource.setSubresourceDef(optRedef.get());
DBDocument document = createDocumentForSubresourceDef(optRedef.get());
subresource.setDocument(document);
subresourceDao.persist(subresource);
// create first member as admin user
return conversionService.convert(subresource, SubresourceRO.class);
}
......
......@@ -5,6 +5,7 @@ import eu.europa.ec.edelivery.smp.data.ui.exceptions.ErrorResponseRO;
import eu.europa.ec.edelivery.smp.error.exceptions.SMPResponseStatusException;
import eu.europa.ec.edelivery.smp.exceptions.BadRequestException;
import eu.europa.ec.edelivery.smp.exceptions.ErrorBusinessCode;
import eu.europa.ec.edelivery.smp.exceptions.MalformedIdentifierException;
import eu.europa.ec.edelivery.smp.exceptions.SMPRuntimeException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -38,6 +39,10 @@ abstract class AbstractErrorControllerAdvice {
BadRequestException ex = (BadRequestException)runtimeException;
response = buildAndLog(UNPROCESSABLE_ENTITY, ex.getErrorBusinessCode(), ex.getMessage(), ex);
}
else if (runtimeException instanceof MalformedIdentifierException){
MalformedIdentifierException ex = (MalformedIdentifierException)runtimeException;
response = buildAndLog(BAD_REQUEST, ErrorBusinessCode.FORMAT_ERROR, ex.getMessage(), ex);
}
else {
response = buildAndLog(INTERNAL_SERVER_ERROR, TECHNICAL, "Unexpected technical error occurred.", runtimeException);
}
......
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