Optimize save of a service.
This commit is contained in:
parent
90299767f2
commit
7589427871
|
@ -1,5 +1,8 @@
|
|||
package eu.dnetlib.developers.entities;
|
||||
|
||||
import eu.dnetlib.developers.dto.ServiceForm;
|
||||
import eu.dnetlib.developers.dto.ServiceRequest;
|
||||
import eu.dnetlib.developers.dto.ServiceResponse;
|
||||
import eu.dnetlib.developers.utils.StringListConverter;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
@ -30,15 +33,21 @@ public class RegisteredService {
|
|||
this.creationDate = new Date();
|
||||
}
|
||||
|
||||
public RegisteredService(String owner, String name, String url, String keyType, String description, String frequency, List<String> target, String issuer) {
|
||||
public RegisteredService(String owner, String issuer) {
|
||||
this.owner = owner;
|
||||
this.name = name;
|
||||
this.keyType = keyType;
|
||||
this.description = description;
|
||||
this.frequency = frequency;
|
||||
this.target = target;
|
||||
this.creationDate = new Date();
|
||||
this.issuer = issuer;
|
||||
this.creationDate = new Date();
|
||||
}
|
||||
|
||||
public void setService(ServiceForm form, ServiceResponse response) {
|
||||
this.clientId = response.getClientId();
|
||||
this.name = form.getName();
|
||||
this.registrationAccessToken = response.getRegistrationAccessToken();
|
||||
this.keyType = form.getKeyType();
|
||||
this.url = form.getUrl();
|
||||
this.description = form.getDescription();
|
||||
this.frequency = form.getFrequency();
|
||||
this.target = form.getTarget();
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
|
|
|
@ -80,7 +80,7 @@ public class APIService {
|
|||
api.setService(service);
|
||||
api.setDetails(readService(service.getClientId(), service.getRegistrationAccessToken()));
|
||||
} else {
|
||||
api.setService(new RegisteredService(authentication.getSub(), form.getName(), form.getUrl(), form.getKeyType(), form.getDescription(), form.getFrequency(), form.getTarget(), issuer));
|
||||
api.setService(new RegisteredService(authentication.getSub(), issuer));
|
||||
}
|
||||
String keyType = form.getKeyType();
|
||||
if(keyType != null && keyType.equals("uri")) {
|
||||
|
@ -109,14 +109,7 @@ public class APIService {
|
|||
throw new ForbiddenException("You are not allowed to own more than 5 services.");
|
||||
}
|
||||
}
|
||||
api.getService().setKeyType(form.getKeyType());
|
||||
api.getService().setUrl(form.getUrl());
|
||||
api.getService().setDescription(form.getDescription());
|
||||
api.getService().setFrequency(form.getFrequency());
|
||||
api.getService().setTarget(form.getTarget());
|
||||
api.getService().setName(request.getClientName());
|
||||
api.getService().setClientId(response.getClientId());
|
||||
api.getService().setRegistrationAccessToken(response.getRegistrationAccessToken());
|
||||
api.getService().setService(form, response);
|
||||
api.setService(this.dao.save(api.getService()));
|
||||
api.setDetails(response);
|
||||
return api;
|
||||
|
|
Loading…
Reference in New Issue