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;
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;
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;
public ResponseEntity<Object> getEiTypeIdentifiers( //
) {
List<String> result = new ArrayList<>();
- for (EiType eiType : this.eiTypes.getAllInfoTypes()) {
+ for (InfoType eiType : this.eiTypes.getAllInfoTypes()) {
result.add(eiType.getId());
}
try {
List<String> 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());
}
public ResponseEntity<Object> 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);
public ResponseEntity<Object> 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);
}
public ResponseEntity<Object> 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);
.onErrorResume(throwable -> Mono.just(ErrorResponse.create(throwable, HttpStatus.NOT_FOUND)));
}
- private Mono<EiJob> startEiJob(EiJob newEiJob) {
- return this.producerCallbacks.startInfoSubscriptionJob(newEiJob, eiProducers) //
+ private Mono<InfoJob> 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<EiJob> validatePutEiJob(String eiJobId, A1eEiJobInfo eiJobInfo) {
+ private Mono<InfoJob> 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);
}
}
+ 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 {
}
}
- 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) //
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());
}
}