Commit fb964b1c authored by Spiros Koulouzis's avatar Spiros Koulouzis

Added delete all

parent f8bf53aa
...@@ -174,7 +174,7 @@ Accept: application/json ...@@ -174,7 +174,7 @@ Accept: application/json
}, { }, {
"name" : "...", "name" : "...",
"id" : "...", "id" : "...",
"type" : "PRIVATE", "type" : "PUBLIC",
"attributes" : { "attributes" : {
"property1" : "...", "property1" : "...",
"property2" : "..." "property2" : "..."
...@@ -429,7 +429,7 @@ Content-Type: application/json ...@@ -429,7 +429,7 @@ Content-Type: application/json
}, { }, {
"name" : "...", "name" : "...",
"id" : "...", "id" : "...",
"type" : "PUBLIC", "type" : "PRIVATE",
"attributes" : { "attributes" : {
"property1" : "...", "property1" : "...",
"property2" : "..." "property2" : "..."
......
...@@ -17,6 +17,7 @@ package nl.uva.sne.drip.api.service; ...@@ -17,6 +17,7 @@ package nl.uva.sne.drip.api.service;
import java.util.List; import java.util.List;
import nl.uva.sne.drip.api.dao.CloudCredentialsDao; import nl.uva.sne.drip.api.dao.CloudCredentialsDao;
import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.commons.v1.types.CloudCredentials; import nl.uva.sne.drip.commons.v1.types.CloudCredentials;
import nl.uva.sne.drip.commons.v1.types.User; import nl.uva.sne.drip.commons.v1.types.User;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -47,12 +48,18 @@ public class CloudCredentialsService { ...@@ -47,12 +48,18 @@ public class CloudCredentialsService {
@PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))") @PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public CloudCredentials findOne(String id) { public CloudCredentials findOne(String id) {
CloudCredentials creds = dao.findOne(id); CloudCredentials creds = dao.findOne(id);
if (creds == null) {
throw new NotFoundException();
}
return creds; return creds;
} }
@PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))") @PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public CloudCredentials delete(String id) { public CloudCredentials delete(String id) {
CloudCredentials creds = dao.findOne(id); CloudCredentials creds = dao.findOne(id);
if (creds == null) {
throw new NotFoundException();
}
dao.delete(creds); dao.delete(creds);
return creds; return creds;
} }
......
...@@ -69,7 +69,11 @@ public class DeployClusterService { ...@@ -69,7 +69,11 @@ public class DeployClusterService {
@PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))") @PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public ClusterCredentials findOne(String id) { public ClusterCredentials findOne(String id) {
return dao.findOne(id); ClusterCredentials creds = dao.findOne(id);
if (creds == null) {
throw new NotFoundException();
}
return creds;
} }
@PostFilter("(filterObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))") @PostFilter("(filterObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
...@@ -79,9 +83,12 @@ public class DeployClusterService { ...@@ -79,9 +83,12 @@ public class DeployClusterService {
@PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))") @PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public ClusterCredentials delete(String id) { public ClusterCredentials delete(String id) {
ClusterCredentials cred = dao.findOne(id); ClusterCredentials creds = dao.findOne(id);
dao.delete(cred); if (creds == null) {
return cred; throw new NotFoundException();
}
dao.delete(creds);
return creds;
} }
public ClusterCredentials save(ClusterCredentials clusterCred) { public ClusterCredentials save(ClusterCredentials clusterCred) {
......
...@@ -187,7 +187,12 @@ public class PlannerService { ...@@ -187,7 +187,12 @@ public class PlannerService {
@PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))") @PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public Plan findOne(String lowiID) { public Plan findOne(String lowiID) {
return planDao.findOne(lowiID); Plan plan = planDao.findOne(lowiID);
if (plan == null) {
throw new NotFoundException();
}
return plan;
} }
@PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))") @PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
......
...@@ -20,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -20,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import nl.uva.sne.drip.api.dao.ScriptDao; import nl.uva.sne.drip.api.dao.ScriptDao;
import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.commons.v1.types.Script; import nl.uva.sne.drip.commons.v1.types.Script;
import nl.uva.sne.drip.commons.v1.types.User; import nl.uva.sne.drip.commons.v1.types.User;
import org.springframework.security.access.prepost.PostAuthorize; import org.springframework.security.access.prepost.PostAuthorize;
...@@ -47,12 +48,18 @@ public class UserScriptService { ...@@ -47,12 +48,18 @@ public class UserScriptService {
@PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))") @PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public Script findOne(String id) { public Script findOne(String id) {
Script script = dao.findOne(id); Script script = dao.findOne(id);
if (script == null) {
throw new NotFoundException();
}
return script; return script;
} }
@PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))") @PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public Script delete(String id) { public Script delete(String id) {
Script script = dao.findOne(id); Script script = dao.findOne(id);
if (script == null) {
throw new NotFoundException();
}
dao.delete(script); dao.delete(script);
return script; return script;
} }
......
...@@ -33,7 +33,6 @@ import org.springframework.web.bind.annotation.RequestMethod; ...@@ -33,7 +33,6 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import nl.uva.sne.drip.api.service.UserService; import nl.uva.sne.drip.api.service.UserService;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
......
...@@ -31,7 +31,6 @@ import org.springframework.web.multipart.MultipartFile; ...@@ -31,7 +31,6 @@ import org.springframework.web.multipart.MultipartFile;
import nl.uva.sne.drip.api.exception.NotFoundException; import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.commons.v1.types.Script; import nl.uva.sne.drip.commons.v1.types.Script;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import nl.uva.sne.drip.api.dao.ScriptDao;
import nl.uva.sne.drip.api.service.UserScriptService; import nl.uva.sne.drip.api.service.UserScriptService;
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment