@Test @Transactional public void testInitialize() { Category category = categoryDao.get(1L); categoryDao.initialize(category); Set<Book> books = category.getBooks(); }
@RequestMapping(value = "/create-category", method = RequestMethod.POST) public String createCategory( Model model, @ModelAttribute("category") @Valid Category category, Errors errors, @RequestParam("name") String name, @RequestParam("description") String description) { model.addAttribute("title", "Create Category"); Category newCategory = new Category(HtmlUtils.htmlEscape(name), HtmlUtils.htmlEscape(description)); if (errors.hasErrors()) { model.addAttribute("category", category); return "create-category"; } /* * What to do if there is no error * We need a DAO and Service to add category into the database */ try { categoryService.createCategory(newCategory); model.addAttribute( "success", "<div class=\"info\">Succesfully Created <p> <a href='manage-category.html'>Go back to Management Page</a></div>"); // Add success message category.setName(""); // Reset form field category.setDescription(""); // Reset form field } catch (EJBException e) { model.addAttribute("error", e.getMessage()); } return "create-category"; }
@RequestMapping(value = "/edit-category/{categoryId}", method = RequestMethod.POST) public String doEditCategory( @ModelAttribute("category") @Valid Category category, Errors errors, @PathVariable String categoryId, @RequestParam("name") String name, @RequestParam("description") String description, Model model) { model.addAttribute("title", "Edit Category"); if (errors.hasErrors()) { model.addAttribute("category", category); return "edit-category"; } category = categoryService.getCategory(Integer.parseInt(HtmlUtils.htmlEscape(categoryId))); if (category == null) { return "redirect:manage-category.html"; } category.setDescription(description); category.setName(name); categoryService.updateCategory(category); model.addAttribute( "info", "<div class=\"info\">Succesfully Updated <p> <a href='../manage-category.html'>Go back to Management Page</a></div>"); return "edit-category"; }
/** * Deletes an existing Category Validation: Check if category exists, Check if validation string * equals catgory name * * @param cat Category Object to be removed * @param validation String to validate if the user surely wants to remove the Category * @return true if Category Object is removed, returns false if this is not the case. */ public boolean deleteCategory(Category cat, String validation) { if (validation.equals(cat.getName())) { for (Category c : categoryList) { if (c.getName().equals(cat.getName())) { categoryList.remove(c); return true; } } } return false; }
private CV createCV() { CV cv = new CV(); Category category = new Category(); category.setName("Technology"); cv.setCategory(Collections.singletonList(category)); User user = new User(); user.setGender(Gender.FEMALE); user.setName("Ann"); cv.setOwner(user); cv.setText("Python, Java, Ruby"); cv.setTitle("Software developer"); return cv; }
public static CategoryDTO toDTO(Category category, UriInfo uriInfo) { CategoryDTO dto = new CategoryDTO(); dto.id = category.getId(); dto.name = category.getName(); Collection<ServiceLink> ls = new LinkedServiceBuilder() .add("GET", "GET", UriBuilderUtil.getCategory(uriInfo, dto.id)) .add("INSERT", "PUT", UriBuilderUtil.insertCategory(uriInfo)) .add("UPDATE", "POST", UriBuilderUtil.updateCategory(uriInfo, dto.id)) .add("DELETE", "DELETE", UriBuilderUtil.deleteCategory(uriInfo, dto.id)) .add( "INSERT-IN", "PUT", UriBuilderUtil.insertProductForCategory(uriInfo.getBaseUriBuilder(), dto.id)) .build(); dto.links = ls; return dto; }
@Override public void updateBook(String oldisbn, Book book) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String date = sdf.format(book.getPubDate()); this.jdbcTemplate.update( new PreparedStatementCreator() { @Override public PreparedStatement createPreparedStatement(Connection con) throws SQLException { String query = "update " + bookTable + " set isbn = ?, title = ?, description = ?, price = ?, publisher = ?, pubDate = ?, edition = ?, pages = ? where isbn = ?"; PreparedStatement ps = con.prepareStatement(query); ps.setString(1, book.getIsbn()); ps.setString(2, book.getTitle()); ps.setString(3, book.getDescription()); ps.setDouble(4, book.getPrice()); ps.setString(5, book.getPublisher()); ps.setString(6, date); ps.setInt(7, book.getEdition()); ps.setInt(8, book.getPages()); ps.setString(9, oldisbn); return ps; } }); this.jdbcTemplate.update(getPSCForRemoving(bookCategoriesTable, "isbn", book.getIsbn())); this.jdbcTemplate.update(getPSCForRemoving(bookAuthorTable, "isbn", book.getIsbn())); List<Category> categories = book.getCategories(); for (Category category : categories) { this.jdbcTemplate.update( getPSCForInsertingBookCategory(book.getIsbn(), category.getCategoryId())); } List<Author> authors = book.getAuthors(); for (Author author : authors) { this.jdbcTemplate.update(getPSCForInsertingBookAuthor(book.getIsbn(), author.getAuthorID())); } }
public Category editCategory( Long categoryId, String name, String description, String overpassKeyValue, User updateUser) { if (updateUser == null || !updateUser.isCategoryWrite() || name.isEmpty()) { return null; } EntityTransaction transaction = startSaveTransaction(); Category category = getCategoryById(categoryId); if (category != null) { category.setName(name); category.setDescription(description); category.setOverpassKeyValue(overpassKeyValue); category.setUpdateUser(updateUser); category.setUpdateTimestamp(new Timestamp(new Date().getTime())); } try { entityManager.persist(category); transaction.commit(); return category; } catch (Exception e) { transaction.rollback(); } return null; }
public static CategoryProductsDTO toCategoryProductsDTO(Category category, UriInfo uriInfo) { CategoryProductsDTO dto = new CategoryProductsDTO(); dto.id = category.getId(); dto.name = category.getName(); Collection<ServiceLink> ls = new LinkedServiceBuilder() .add("GET", "GET", UriBuilderUtil.getCategory(uriInfo, dto.id)) .add("INSERT", "PUT", UriBuilderUtil.insertCategory(uriInfo)) .add("UPDATE", "POST", UriBuilderUtil.updateCategory(uriInfo, dto.id)) .add("DELETE", "DELETE", UriBuilderUtil.deleteCategory(uriInfo, dto.id)) .add( "INSERT-IN", "PUT", UriBuilderUtil.insertProductForCategory(uriInfo.getBaseUriBuilder(), dto.id)) .add("UP", "GET", uriInfo.getBaseUriBuilder().path("categories").build()) .build(); dto.links = ls; for (Product p : category.getProducts()) { dto.products.add(Converter.toDTO(p, dto.id, uriInfo)); } return dto; }
@Override public void insertBook(Book book) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String date = sdf.format(book.getPubDate()); this.jdbcTemplate.update( new PreparedStatementCreator() { @Override public PreparedStatement createPreparedStatement(Connection con) throws SQLException { String query = "insert into " + bookTable + " (isbn, title, description, price, publisher, pubdate, edition, pages) values (?, ?, ?, ?, ?, ?, ?, ?);"; PreparedStatement ps = con.prepareStatement(query); ps.setString(1, book.getIsbn()); ps.setString(2, book.getTitle()); ps.setString(3, book.getDescription()); ps.setDouble(4, book.getPrice()); ps.setString(5, book.getPublisher()); ps.setString(6, date); ps.setInt(7, book.getEdition()); ps.setInt(8, book.getPages()); return ps; } }); List<Category> categories = book.getCategories(); for (Category category : categories) { this.jdbcTemplate.update( getPSCForInsertingBookCategory(book.getIsbn(), category.getCategoryId())); } List<Author> authors = book.getAuthors(); for (Author author : authors) { this.jdbcTemplate.update(getPSCForInsertingBookAuthor(book.getIsbn(), author.getAuthorID())); } }
@Override public void start(Stage stage) throws Exception { // ----------MENU---------- MenuBar menuBar = new MenuBar(); Menu menuFile = new Menu("File"); MenuItem menuItemPurchase = new MenuItem("New Purchase"); MenuItem menuItemStore = new MenuItem("New Store"); MenuItem menuItemCategory = new MenuItem("New Category"); MenuItem menuItemExit = new MenuItem("Exit"); menuFile.getItems().addAll(menuItemPurchase, menuItemStore, menuItemCategory, menuItemExit); Menu menuHelp = new Menu("Help"); menuBar.getMenus().addAll(menuFile, menuHelp); // ----------TOOLBAR---------- ToolBar toolBar = new ToolBar(); Button buttonPurchase = new Button(); Button buttonStore = new Button(); Button buttonCategory = new Button(); buttonPurchase.setGraphic(new ImageView("/pictures/purchase.png")); buttonStore.setGraphic(new ImageView("/pictures/store.png")); buttonCategory.setGraphic(new ImageView("/pictures/category.png")); toolBar.getItems().addAll(buttonPurchase, buttonStore, buttonCategory); buttonStore.setOnAction( new EventHandler<ActionEvent>() { public void handle(ActionEvent actionEvent) { Stage stage = new Stage(); try { new StoreWindows().start(stage); } catch (Exception e) { e.printStackTrace(); } } }); // ----------WORKSPACE---------- GridPane gridPane = new GridPane(); gridPane.setAlignment(Pos.CENTER); gridPane.setVgap(10); gridPane.setHgap(10); gridPane.setPadding(new Insets(0, 25, 25, 0)); Label storeLabel = new Label("Store: "); storeLabel.setId("simpleLabel"); gridPane.add(storeLabel, 0, 1); final ComboBox<String> stores = new ComboBox<String>(); gridPane.add(stores, 1, 1); Label categoryLabel = new Label("Category: "); categoryLabel.setId("simpleLabel"); gridPane.add(categoryLabel, 2, 1); final ComboBox<String> categories = new ComboBox<String>(); gridPane.add(categories, 3, 1); Button bCount = new Button("Count"); HBox hBox = new HBox(10); hBox.setAlignment(Pos.BOTTOM_RIGHT); hBox.getChildren().add(bCount); gridPane.add(hBox, 4, 1); FlowPane flowPane1 = new FlowPane(); flowPane1.setAlignment(Pos.CENTER); flowPane1.setPadding(new Insets(10, 25, 25, 10)); final Text spentTitle = new Text("SPENT: "); spentTitle.setId("headline"); flowPane1.getChildren().add(spentTitle); // ----------DATABASE---------- Label statusLabel = new Label(); DaoFactory daoFactory = new MySQLDaoFactory(); try { Connection connection = daoFactory.getConnection(); statusLabel.setText("Database connection: success"); StoreDao storeDao = new MySQLStoreDao(connection); ArrayList<Store> storeList = (ArrayList) storeDao.getStores(); for (Store store : storeList) { stores.getItems().add(store.getName()); } CategoryDao categoryDao = new MySQLCategoryDao(connection); ArrayList<Category> categoryList = (ArrayList) categoryDao.getCategories(); for (Category category : categoryList) { categories.getItems().add(category.getTitle()); } } catch (SQLException e) { statusLabel.setText("Database connection: failed"); } FlowPane footer = new FlowPane(); footer.setPadding(new Insets(10, 10, 10, 10)); footer.getChildren().add(statusLabel); bCount.setOnAction( new EventHandler<ActionEvent>() { public void handle(ActionEvent actionEvent) { try { PurchaseDao purchaseDao = new MySQLPurchaseDao(new MySQLDaoFactory().getConnection()); spentTitle.setText( "SPENT: " + purchaseDao.showSpent(stores.getValue(), categories.getValue())); } catch (SQLException e) { e.printStackTrace(); } } }); // ----------VIEW---------- Scene scene = new Scene(new VBox(), 800, 600); scene.getStylesheets().add("css/style.css"); ((VBox) scene.getRoot()).getChildren().addAll(menuBar, toolBar, gridPane, flowPane1, footer); stage.setScene(scene); stage.setTitle("Cash Organizer"); stage.getIcons().add(new Image("pictures/icon.png")); stage.show(); }
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); String username = (String) session.getAttribute("username"); String curCategId = (String) session.getAttribute("curCategId"); response.setContentType("text/html;charset=UTF-8"); String action = request.getParameter("action"); PrintWriter out = response.getWriter(); System.out.println("Action = " + action); if (action.equalsIgnoreCase("showCategory")) { ArrayList<Category> categories = new ArrayList<Category>(joinOp.GetCategByUsername(username)); out.println("<div class='kategori'>"); out.println("<div id='categoryAll' onclick='showTaskList(0);'>All</div>"); out.println("</div>"); for (Category categ : categories) { out.println("<div class='kategori'>"); out.println( "<div id='category" + categ.getId_category() + "'" + "onclick='showTaskList(" + categ.getId_category() + ");'>" + categ.getName() + "</div>"); if (username.equals(categ.getCateg_creator())) { out.println( "<div class='removeCategory' id='removeCateg" + categ.getId_category() + "' onclick='return removeCategory(" + categ.getId_category() + ");'>x</div>"); } out.println("</div>"); } } else if (action.equalsIgnoreCase("addCategory")) { String categName = request.getParameter("name"); String[] authUsers = request.getParameter("authUsers").split(","); categoryOp.InsertNewCategory(new Category("", categName, username)); String newCategId = categoryOp.FetchIdByName(categName); caurelationOp.InsertCaurelation(new Caurelation("", newCategId, username)); ucrelationOp.InsertUcrelation(new Ucrelation("", username, newCategId)); if (authUsers.length != 0) { for (String authUser : authUsers) { if (userOp.ListAllUsernames().contains(authUser)) { ucrelationOp.InsertUcrelation(new Ucrelation("", authUser.trim(), newCategId)); caurelationOp.InsertCaurelation(new Caurelation("", newCategId, authUser)); } } } } else if (action.equalsIgnoreCase("removeCategory")) { String categId = request.getParameter("code"); ArrayList<String> taskIds = new ArrayList<String>(taskOp.FetchIdsByCategId(categId)); for (String taskId : taskIds) { ttrelationOp.DeleteByTaskId(taskId); utrelationOp.DeleteByTaskId(taskId); tarelationOp.DeleteTarelationByTaskId(taskId); commentOp.DeleteCommentByTaskId(taskId); taskOp.DeleteById(taskId); } ucrelationOp.DeleteByCategId(categId, username); caurelationOp.DeleteCaurelationByCategId(categId); categoryOp.DeleteCategoryById(categId); } else if (action.equalsIgnoreCase("showTaskList")) { String categId = request.getParameter("code"); session.setAttribute("curCategId", categId); ArrayList<Task> tasks = new ArrayList<Task>(joinOp.GetTasksByUsernameAndCategoryId(username, categId)); ArrayList<String> tags; int i = 0; for (Task task : tasks) { i = 0; out.println("<div class='listTugas'>"); out.println( "<a class='listname' id='task" + task.getId_task() + "'" + "onclick='showRinci(" + task.getId_task() + ");'>" + task.getName() + "</a>"); out.println("<div class='listdeadline'>Deadline: " + task.getDeadline() + "</div>"); tags = new ArrayList<String>(joinOp.GetTagNamesByTaskId(task.getId_task())); out.println("<div class='listtag'>Tag: "); while (i < tags.size()) { out.print(tags.get(i)); i++; if (i < tags.size()) { out.print(", "); } } out.println("</div>"); out.println("<div class='liststatus' id='statusTask'>"); if (task.getStatus().equals("T")) { out.println( "<input type='checkbox' id='checkboxTask" + task.getId_task() + "' onclick='changeTaskStatus(" + task.getId_task() + ", this.checked);' checked>"); } else if (task.getStatus().equals("F")) { out.println( "<input type='checkbox' id='checkboxTask" + task.getId_task() + "' onclick='changeTaskStatus(" + task.getId_task() + ", this.checked);'>"); } out.println("Done</div>"); if (username.equals(taskOp.FetchCreatorById(task.getId_task()))) { out.println( "<div class='removeTask'><input type='submit' id='removeTaskBtn" + task.getId_task() + "' onclick='removeTask(" + curCategId + "," + task.getId_task() + ");' value='Remove Task'/></div>"); } out.println("</div>"); } if (caurelationOp.FetchAuthUsersByCategId(categId).contains(username)) { out.println("<a onclick='showBuat();' class='addTask'>+task</a>"); } } else if (action.equalsIgnoreCase("showTaskDetail")) { String taskId = request.getParameter("code"); Task task = taskOp.SelectById(taskId); out.println("<div id='taskdetail'>"); // NAME out.println("<div id='taskdetail_name'>" + task.getName() + "</div><br>"); // STATUS out.println("<br><div>=======================================================</div>"); if (task.getStatus().equalsIgnoreCase("T")) { out.println( "<div id='taskdetail_status'><em>Status : </em>Done " + "<input type='checkbox' onclick='changeTaskStatus(" + task.getId_task() + ", this.checked);' checked/>" + "</div>"); } else { out.println( "<div id='taskdetail_status'>Status : Done " + "<input type='checkbox' onclick='changeTaskStatus(" + task.getId_task() + ", this.checked);'/>" + "</div>"); } // ATTACHMENT ArrayList<Attachment> attachments = joinOp.GetAttachmentFromId_task(task.getId_task()); int extensionIdx; String extension, filename; out.println("<br><div>=======================================================</div>"); out.println("<div><em>Attachment: </em></div>"); out.println("<div id='taskdetail_attachment'>"); for (Attachment item : attachments) { extensionIdx = item.getPath().lastIndexOf('.'); if (extensionIdx > 0) { filename = item.getPath().substring(item.getPath().lastIndexOf('/') + 1); extension = item.getPath().substring(extensionIdx + 1); System.out.println(item.getPath() + " has extension " + extension); // jika gambar if (extension.equalsIgnoreCase("jpg") || extension.equalsIgnoreCase("png") || extension.equalsIgnoreCase("gif")) { System.out.println(filename); out.println("<img src='" + item.getPath() + "' height=\"100\" width=\"100\"/><br>"); out.println("<a href='" + item.getPath() + "'>" + filename + "</a><br>"); // jika video } else if (extension.equalsIgnoreCase("mp4") || extension.equalsIgnoreCase("webm") || extension.equalsIgnoreCase("ogg")) { out.println("<video width=\"320\" height=\"240\" controls>"); out.println("<source src='" + item.getPath() + "' type='video/" + extension + "'>"); out.println("</video><br>"); out.println("<a href='" + item.getPath() + "'>" + filename + "</a><br>"); } else { out.println("<a href='" + item.getPath() + "'>" + filename + "</a><br>"); } } } out.println("</div>"); // DEADLINE out.println("<br><div>=======================================================</div>"); out.println( "<div id='taskdetail_deadline'><em>Deadline: </em>" + task.getDeadline() + "</div>"); // ASSIGNEE out.println("<br><div>=======================================================</div>"); ArrayList<String> assignees = utrelationOp.FetchAssigneeByTaskId(task.getId_task()); out.println("<div id='taskdetail_assignee'><em>Assignee: </em>"); int i = 0; while (i < assignees.size()) { out.println( "<a href='profile.jsp?userprofile=" + assignees.get(i) + "'>" + assignees.get(i) + "</a>"); i++; if (i < assignees.size()) { out.print("; "); } } out.println("</div>"); // KOMENTAR out.println("<br><div>=======================================================</div>"); out.println("<div><em>Comment: </em></div>"); User user; String[] timesplit; ArrayList<Comment> comments = commentOp.FetchCommentByTaskId(task.getId_task()); out.println("<div id='ctotal'>" + comments.size() + " comment(s)</div>"); out.println("<div id='taskdetail_comment'>"); out.println("<div id='commentlist'>"); for (Comment item : comments) { out.println("<div id='comment" + item.getId_comment() + "'>"); user = userOp.SelectUserInfoByUsername(item.getUsername()); timesplit = item.getTimestamp().split(":"); System.out.println("LALALALALA" + timesplit.length); out.println( "<img class='cavatar' src='" + user.getAvatar() + "' style='width:30px; height:30px;'/>"); out.println( "<div class='ctimestamp'>" + timesplit[3] + ":" + timesplit[4] + " - " + timesplit[2] + "/" + timesplit[1] + "</div>"); out.println("<div class='ccontent'>" + item.getContent() + "</div>"); if (username.equals(user.getUsername())) { out.println( "<input type='button' value='Delete' class='cdelete' onclick='delComment(" + item.getId_comment() + ");'/>"); } out.println("</div>"); } out.println("</div>"); out.println("<div id='commentbox'>"); out.println("<textarea id='cbox'></textarea></br>"); out.println("<input type='button' value='Submit' onclick='addComment(" + taskId + ");'/>"); out.println("</div>"); out.println("</div>"); // TAG out.println("<br><div>=======================================================</div>"); ArrayList<Tag> tags = joinOp.GetTagFromId_task(task.getId_task()); out.println("<div id='taskdetail_tag'><em>Tag: </em>"); i = 0; while (i < tags.size()) { out.println(tags.get(i).getName()); i++; if (i < tags.size()) { out.print("; "); } } out.println("</div>"); if (utrelationOp.IsTaskEditable(username, taskId)) { out.println( "<input type='button' value='Edit task' onclick='editTaskDetail(" + task.getId_task() + ");'/>"); } out.println("<input type='button' value='Back' onclick='restore2();'/>"); out.println("</div>"); } else if (action.equalsIgnoreCase("editTaskDetail")) { String taskId = request.getParameter("code"); Task task = taskOp.SelectById(taskId); out.println("<div id='editdetail'>"); out.println("<form>"); out.println("<big style='font-size: 20pt;'>" + task.getName() + "</big><br/>"); out.println( "<br/>Deadline: <input type='date' id='editDeadline' name='editDeadline' value='" + task.getDeadline() + "'><br/>"); out.println( "<br/><div class='assignee'>Assignee: <input type='text' id='editAssignee'" + "name='editAssignee' value='"); ArrayList<String> authUsers = new ArrayList<String>(utrelationOp.FetchAssigneeByTaskId(taskId)); int i = 0; while (i < authUsers.size()) { out.print(authUsers.get(i)); i++; if (i < authUsers.size()) { out.print(","); } } out.print( "' onkeyup=\"multiAutocomp(this, 'getAllUser.jsp');\" onfocusin='multiAutocompClearAll();'></div><br/>"); out.println("<div class='tag'>Tag: <input type='text' id='editTag' name='editTag' value='"); ArrayList<String> tags = new ArrayList<String>(joinOp.GetTagNamesByTaskId(task.getId_task())); i = 0; while (i < tags.size()) { out.print(tags.get(i)); i++; if (i < tags.size()) { out.print(","); } } out.print( "' onkeyup=\"multiAutocomp(this, 'getAllTag.jsp');\" onfocusin='multiAutocompClearAll();'></div><br/>"); out.println("</form><br/>"); if (username.equals(taskOp.FetchCreatorById(task.getId_task()))) { out.println( "<input type='button' id='editremove' onclick='removeTask(" + curCategId + ", " + task.getId_task() + ");' class='button' value='Remove Task'/><br>"); } else if (utrelationOp.FetchAssigneeByTaskId(task.getId_task()).contains(username)) { out.println( "<input type='button' id='editremove' onclick='removeReference(" + curCategId + ", " + task.getId_task() + ");' class='button' value='Remove me from this task'/><br>"); } out.println( "<input type='button' id='editsave' onclick='saveTaskDetail(" + task.getId_task() + ");' class='button' value='Save'/>"); out.println( "<input type='button' id='editback' onclick='restore4();' class='button' value='Back'/>"); out.println("</div>"); } else if (action.equalsIgnoreCase("changeTaskStatus")) { String taskId = request.getParameter("code"); String newStatus = request.getParameter("chkYesNo"); if (newStatus.equals("0")) { taskOp.UpdateStatusWithId("F", taskId); } else if (newStatus.equals("1")) { taskOp.UpdateStatusWithId("T", taskId); } out.println("<div>"); if (newStatus.equals("0")) { out.println( "<input type='checkbox' id='checkboxTask" + taskId + "' " + "onclick='changeTaskStatus(" + taskId + ", this.checked);' checked>"); } else if (newStatus.equals("1")) { out.println( "<input type='checkbox' id='checkboxTask" + taskId + "' " + "onclick='changeTaskStatus(" + taskId + ", this.checked);'>"); } out.println("Done</div>"); } else if (action.equalsIgnoreCase("saveTaskDetail")) { String taskId = request.getParameter("code"); String deadline = request.getParameter("newDeadline"); String[] assignees = request.getParameter("newAssignees").split(","); String[] tags = request.getParameter("newTags").split(","); ArrayList<String> oldAssignees = new ArrayList<String>(utrelationOp.FetchAssigneeByTaskId(taskId)); ArrayList<String> oldTagIds = new ArrayList<String>(joinOp.GetTagsIdByTaskId(taskId)); taskOp.UpdateDeadlineById(deadline, taskId); for (String oldAssignee : oldAssignees) { utrelationOp.DeleteByTaskIdAndUsername(taskId, oldAssignee); } for (String oldTagId : oldTagIds) { ttrelationOp.DeleteByTagId(oldTagId); } for (String assignee : assignees) { if (userOp.ListAllUsernames().contains(assignee.trim())) { utrelationOp.InsertUtrelation(new Utrelation("", taskId, assignee.trim())); if (ucrelationOp.CheckIfUcrelationExists(assignee.trim(), curCategId) == 0) { ucrelationOp.InsertUcrelation(new Ucrelation("", assignee.trim(), curCategId)); } } } for (String tag : tags) { if (tagOp.CheckIfTagExists(tag.trim()) == 0) { tagOp.InsertTag(tag.trim()); } ttrelationOp.InsertTtrelation(new Ttrelation("", taskId, tagOp.SelectIdByName(tag.trim()))); } ArrayList<Task> temp; for (String oldAssignee : oldAssignees) { temp = new ArrayList<Task>(joinOp.GetTasksByUsernameAndCategoryId(oldAssignee, curCategId)); if (temp.isEmpty()) { ucrelationOp.DeleteByCategId(curCategId, oldAssignee); } } for (String oldTagId : oldTagIds) { if (joinOp.CheckTtrelationByTagId(oldTagId) == 0) { tagOp.DeleteById(oldTagId); } } } else if (action.equalsIgnoreCase("addTask")) { String[] assignees = request.getParameter("newTaskAssignee").split(","); String[] tags = request.getParameter("newTaskTags").split(","); String name = request.getParameter("newTaskName"); } else if (action.equalsIgnoreCase("removeTask")) { String taskId = request.getParameter("code"); tarelationOp.DeleteTarelationByTaskId(taskId); ttrelationOp.DeleteByTaskId(taskId); commentOp.DeleteCommentByTaskId(taskId); utrelationOp.DeleteByTaskId(taskId); taskOp.DeleteById(taskId); ArrayList<String> allUsers = new ArrayList<String>(userOp.ListAllUsernames()); ArrayList<Task> temp; for (String user : allUsers) { if (!user.equals(username)) { temp = new ArrayList<Task>(joinOp.GetTasksByUsernameAndCategoryId(user, curCategId)); if (temp.isEmpty()) { ucrelationOp.DeleteByCategId(curCategId, username); } } } } else if (action.equalsIgnoreCase("removeReference")) { String taskId = request.getParameter("code"); utrelationOp.DeleteByTaskId(taskId); ArrayList<Task> temp = new ArrayList<Task>(joinOp.GetTasksByUsernameAndCategoryId(username, curCategId)); if (temp.isEmpty()) { ucrelationOp.DeleteByCategId(curCategId, username); } } else if (action.equalsIgnoreCase("addComment")) { String idtask = request.getParameter("it"); String content = request.getParameter("c"); DateFormat dateFormat = new SimpleDateFormat("yyyy:MM:dd:HH:mm"); Date date = new Date(); String timestamp = dateFormat.format(date).toString(); String avatar = userOp.SelectUserInfoByUsername(username).getAvatar(); commentOp.InsertComment(idtask, username, dateFormat.format(date).toString(), content); String idcomment = commentOp.GetIdByOtherAttributes(idtask, username, content); String message = avatar + ":" + timestamp + ":" + content + ":" + idcomment; out.println(message); } else if (action.equalsIgnoreCase("delComment")) { String idcomment = request.getParameter("ic"); commentOp.DeleteCommentByCommentId(idcomment); out.println(idcomment); } else { System.out.println("No command existed"); } out.close(); }
public static Category toCategory(CategoryDTO categoryDTO) { Category c = new Category(); c.setId(categoryDTO.id); c.setName(categoryDTO.name); return c; }