X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=enrichment-coordinator-service%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fenrichment%2Fcontrollers%2Fa1e%2FA1eController.java;h=4c5f5d0cb849ca0a0a1a015489a1a1831eb24e25;hb=8fd8e9fc86a24be49d61841e381423120a41296d;hp=34d9725eeea390c71e9515313127c82cc97de196;hpb=367608a9f6c71c2aaae45ed8b1099b9c8e51c0f7;p=nonrtric.git diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/a1e/A1eController.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/a1e/A1eController.java index 34d9725e..4c5f5d0c 100644 --- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/a1e/A1eController.java +++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/a1e/A1eController.java @@ -34,6 +34,8 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; import java.lang.invoke.MethodHandles; +import java.net.URI; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; @@ -43,11 +45,11 @@ import org.oransc.enrichment.controllers.ErrorResponse; import org.oransc.enrichment.controllers.VoidResponse; import org.oransc.enrichment.controllers.r1producer.ProducerCallbacks; import org.oransc.enrichment.exceptions.ServiceException; -import org.oransc.enrichment.repository.EiJob; -import org.oransc.enrichment.repository.EiJobs; -import org.oransc.enrichment.repository.EiProducers; -import org.oransc.enrichment.repository.EiType; -import org.oransc.enrichment.repository.EiTypes; +import org.oransc.enrichment.repository.InfoJob; +import org.oransc.enrichment.repository.InfoJobs; +import org.oransc.enrichment.repository.InfoProducers; +import org.oransc.enrichment.repository.InfoType; +import org.oransc.enrichment.repository.InfoTypes; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -76,13 +78,13 @@ public class A1eController { ApplicationConfig applicationConfig; @Autowired - private EiJobs eiJobs; + private InfoJobs eiJobs; @Autowired - private EiTypes eiTypes; + private InfoTypes eiTypes; @Autowired - private EiProducers eiProducers; + private InfoProducers infoProducers; @Autowired ProducerCallbacks producerCallbacks; @@ -101,7 +103,7 @@ public class A1eController { public ResponseEntity getEiTypeIdentifiers( // ) { List result = new ArrayList<>(); - for (EiType eiType : this.eiTypes.getAllInfoTypes()) { + for (InfoType eiType : this.eiTypes.getAllInfoTypes()) { result.add(eiType.getId()); } @@ -159,7 +161,7 @@ public class A1eController { try { List result = new ArrayList<>(); if (owner != null) { - for (EiJob job : this.eiJobs.getJobsForOwner(owner)) { + for (InfoJob job : this.eiJobs.getJobsForOwner(owner)) { if (eiTypeId == null || job.getTypeId().equals(eiTypeId)) { result.add(job.getId()); } @@ -193,7 +195,7 @@ public class A1eController { public ResponseEntity getIndividualEiJob( // @PathVariable("eiJobId") String eiJobId) { try { - EiJob job = this.eiJobs.getJob(eiJobId); + InfoJob job = this.eiJobs.getJob(eiJobId); return new ResponseEntity<>(gson.toJson(toEiJobInfo(job)), HttpStatus.OK); } catch (Exception e) { return ErrorResponse.create(e, HttpStatus.NOT_FOUND); @@ -216,15 +218,15 @@ public class A1eController { public ResponseEntity getEiJobStatus( // @PathVariable("eiJobId") String eiJobId) { try { - EiJob job = this.eiJobs.getJob(eiJobId); + InfoJob job = this.eiJobs.getJob(eiJobId); return new ResponseEntity<>(gson.toJson(toEiJobStatus(job)), HttpStatus.OK); } catch (Exception e) { return ErrorResponse.create(e, HttpStatus.NOT_FOUND); } } - private A1eEiJobStatus toEiJobStatus(EiJob job) { - return this.eiProducers.isJobEnabled(job) ? new A1eEiJobStatus(A1eEiJobStatus.EiJobStatusValues.ENABLED) + private A1eEiJobStatus toEiJobStatus(InfoJob job) { + return this.infoProducers.isJobEnabled(job) ? new A1eEiJobStatus(A1eEiJobStatus.EiJobStatusValues.ENABLED) : new A1eEiJobStatus(A1eEiJobStatus.EiJobStatusValues.DISABLED); } @@ -249,8 +251,8 @@ public class A1eController { public ResponseEntity deleteIndividualEiJob( // @PathVariable("eiJobId") String eiJobId) { try { - EiJob job = this.eiJobs.getJob(eiJobId); - this.eiJobs.remove(job, this.eiProducers); + InfoJob job = this.eiJobs.getJob(eiJobId); + this.eiJobs.remove(job, this.infoProducers); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } catch (Exception e) { return ErrorResponse.create(e, HttpStatus.NOT_FOUND); @@ -290,18 +292,20 @@ public class A1eController { .onErrorResume(throwable -> Mono.just(ErrorResponse.create(throwable, HttpStatus.NOT_FOUND))); } - private Mono startEiJob(EiJob newEiJob) { - return this.producerCallbacks.startInfoSubscriptionJob(newEiJob, eiProducers) // + private Mono startEiJob(InfoJob newEiJob) { + return this.producerCallbacks.startInfoSubscriptionJob(newEiJob, infoProducers) // .doOnNext(noOfAcceptingProducers -> this.logger.debug( "Started EI job {}, number of activated producers: {}", newEiJob.getId(), noOfAcceptingProducers)) // .flatMap(noOfAcceptingProducers -> Mono.just(newEiJob)); } - private Mono validatePutEiJob(String eiJobId, A1eEiJobInfo eiJobInfo) { + private Mono validatePutEiJob(String eiJobId, A1eEiJobInfo eiJobInfo) { try { - EiType eiType = this.eiTypes.getType(eiJobInfo.eiTypeId); + InfoType eiType = this.eiTypes.getType(eiJobInfo.eiTypeId); validateJsonObjectAgainstSchema(eiType.getJobDataSchema(), eiJobInfo.jobDefinition); - EiJob existingEiJob = this.eiJobs.get(eiJobId); + InfoJob existingEiJob = this.eiJobs.get(eiJobId); + validateUri(eiJobInfo.jobResultUri); + validateUri(eiJobInfo.statusNotificationUri); if (existingEiJob != null && !existingEiJob.getTypeId().equals(eiJobInfo.eiTypeId)) { throw new ServiceException("Not allowed to change type for existing EI job", HttpStatus.CONFLICT); @@ -312,6 +316,15 @@ public class A1eController { } } + private void validateUri(String url) throws URISyntaxException, ServiceException { + if (url != null && !url.isEmpty()) { + URI uri = new URI(url); + if (!uri.isAbsolute()) { + throw new ServiceException("URI: " + url + " is not absolute", HttpStatus.CONFLICT); + } + } + } + private void validateJsonObjectAgainstSchema(Object schemaObj, Object object) throws ServiceException { if (schemaObj != null) { // schema is optional for now try { @@ -330,8 +343,8 @@ public class A1eController { } } - private EiJob toEiJob(A1eEiJobInfo info, String id, EiType type) { - return EiJob.builder() // + private InfoJob toEiJob(A1eEiJobInfo info, String id, InfoType type) { + return InfoJob.builder() // .id(id) // .typeId(type.getId()) // .owner(info.owner) // @@ -345,7 +358,7 @@ public class A1eController { return new A1eEiTypeInfo(); } - private A1eEiJobInfo toEiJobInfo(EiJob s) { + private A1eEiJobInfo toEiJobInfo(InfoJob s) { return new A1eEiJobInfo(s.getTypeId(), s.getJobData(), s.getOwner(), s.getTargetUrl(), s.getJobStatusUrl()); } }