diff --git a/src/main/java/edu/mostafa/abac/web/controllers/ToDoController.java b/src/main/java/edu/mostafa/abac/web/controllers/ToDoController.java deleted file mode 100644 index 23dd6c6..0000000 --- a/src/main/java/edu/mostafa/abac/web/controllers/ToDoController.java +++ /dev/null @@ -1,48 +0,0 @@ -package edu.mostafa.abac.web.controllers; - -import java.util.List; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.security.access.prepost.PostAuthorize; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.bind.annotation.ResponseStatus; -import org.springframework.web.bind.annotation.RestController; - -import edu.mostafa.abac.web.model.ToDoItem; -import edu.mostafa.abac.web.services.ToDoService; - -@RestController -@RequestMapping("/todo") -public class ToDoController { - private static final Logger log = LoggerFactory.getLogger(ToDoController.class); - - @Autowired - ToDoService toDoService; - - @RequestMapping(value = "", method = RequestMethod.GET, produces = {"application/json"}) - @ResponseStatus(HttpStatus.OK) - @ResponseBody - public List getToDos() { - log.info("[getToDos] started ..."); - List result = toDoService.getToDos(); - log.info("[getToDos] done, {} items.", result == null? 0 : result.size()); - return result; - } - - @RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = {"application/json"}) - @ResponseStatus(HttpStatus.OK) - @ResponseBody - @PostAuthorize("hasPermission(returnObject,'VIEW_TODO')") - public ToDoItem getToDo(@PathVariable("id") Long id) { - log.info("[getToDo] started ..."); - ToDoItem result = toDoService.getToDo(id); - log.info("[getToDo] done, result: " + result); - return result; - } -} diff --git a/src/main/java/edu/mostafa/abac/web/model/ToDoItem.java b/src/main/java/edu/mostafa/abac/web/model/ToDoItem.java deleted file mode 100644 index 3d1ae35..0000000 --- a/src/main/java/edu/mostafa/abac/web/model/ToDoItem.java +++ /dev/null @@ -1,82 +0,0 @@ -package edu.mostafa.abac.web.model; - -public class ToDoItem { - private Long id; - private String desc; - private String owner; - - - - public ToDoItem(Long id, String desc) { - super(); - this.id = id; - this.desc = desc; - } - - public ToDoItem(Long id, String desc, String owner) { - super(); - this.id = id; - this.desc = desc; - this.owner = owner; - } - - public String getDesc() { - return desc; - } - - public void setDesc(String desc) { - this.desc = desc; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getOwner() { - return owner; - } - - public void setOwner(String owner) { - this.owner = owner; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((desc == null) ? 0 : desc.hashCode()); - result = prime * result + ((id == null) ? 0 : id.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - ToDoItem other = (ToDoItem) obj; - if (desc == null) { - if (other.desc != null) - return false; - } else if (!desc.equals(other.desc)) - return false; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) - return false; - return true; - } - - @Override - public String toString() { - return "{id:" + id + ", desc:" + desc + ", owner:" + owner + "}"; - } -} diff --git a/src/main/java/edu/mostafa/abac/web/services/ToDoService.java b/src/main/java/edu/mostafa/abac/web/services/ToDoService.java deleted file mode 100644 index f7ade0c..0000000 --- a/src/main/java/edu/mostafa/abac/web/services/ToDoService.java +++ /dev/null @@ -1,14 +0,0 @@ -package edu.mostafa.abac.web.services; - -import java.util.List; - -import edu.mostafa.abac.web.model.ToDoItem; - -public interface ToDoService { - public List getToDos(); - public ToDoItem getToDo(Long id); - public void addToDo(ToDoItem item); - public void updateToDo(ToDoItem item); - public void deleteToDo(ToDoItem item); - -} diff --git a/src/main/java/edu/mostafa/abac/web/services/impl/ToDoServiceImpl.java b/src/main/java/edu/mostafa/abac/web/services/impl/ToDoServiceImpl.java deleted file mode 100644 index b04fa23..0000000 --- a/src/main/java/edu/mostafa/abac/web/services/impl/ToDoServiceImpl.java +++ /dev/null @@ -1,65 +0,0 @@ -package edu.mostafa.abac.web.services.impl; - -import java.util.ArrayList; -import java.util.List; - -import org.springframework.stereotype.Component; - -import edu.mostafa.abac.web.model.ToDoItem; -import edu.mostafa.abac.web.services.ToDoService; - -@Component -public class ToDoServiceImpl implements ToDoService { - private List items = new ArrayList(5); - - public ToDoServiceImpl() { - items.add(new ToDoItem(1l, "Item 1", "dev1")); - items.add(new ToDoItem(2l, "Item 2", "dev2")); - items.add(new ToDoItem(3l, "Item 3", "pm1")); - items.add(new ToDoItem(4l, "Item 4", "pm2")); - items.add(new ToDoItem(5l, "Item 5", "admin")); - } - - @Override - public List getToDos() { - return items; - } - - - @Override - public void addToDo(ToDoItem item) { - items.add(item); - - } - - @Override - public void updateToDo(ToDoItem item) { - for(ToDoItem cItem : items) { - if(cItem.getId().equals(item.getId())){ - cItem.setDesc(item.getDesc()); - } - } - } - - @Override - public void deleteToDo(ToDoItem item) { - ToDoItem existing = null; - for(ToDoItem cItem : items) { - if(cItem.getId().equals(item.getId())){ - existing = cItem; - } - } - items.remove(existing); - } - - @Override - public ToDoItem getToDo(Long id) { - for(ToDoItem cItem : items) { - if(cItem.getId().equals(id)){ - return cItem; - } - } - return null; - } - -}