// @Post("/projects/create") public static void doCreate(Project project) { User user = getLoggedin(); List<ProjectTemplate> templates = ProjectTemplate.getTemplates(user, false); if (params.get("project.deadline") == "") { project.deadline = null; } Validation.valid("Project", project); if (Validation.hasErrors()) { displayValidationMessage(); render("projects/create.html", project, templates); } ActionResult res; res = project.createAndGetResult(user); if (!res.isSuccess()) { displayError(res.getMessage(), "save-project"); render("projects/create.html", project, templates); } res = project.assignCreator(user, null); if (!res.isSuccess()) { displayError(res.getMessage(), "set-creator-when-save-project"); render("projects/create.html", project, templates); } project.copyFromTemplate(user, project.fromTemplate); if (!res.isSuccess()) { displayWarning(res.getMessage(), "save-activity-when-create-project"); } structure(project.id); }
@Test public void detachLabel() { // Given Project project = Project.findByOwnerAndProjectName("yobi", "projectYobi"); Label label1 = new Label("OS", "linux"); label1.save(); project.labels.add(label1); project.update(); Long labelId = label1.id; assertThat(project.labels.contains(label1)).isTrue(); Map<String, String> data = new HashMap<>(); data.put("_method", "DELETE"); User admin = User.findByLoginId("admin"); String user = "******"; String projectName = "projectYobi"; // When Result result = callAction( controllers.routes.ref.ProjectApp.detachLabel(user, projectName, labelId), fakeRequest(POST, routes.ProjectApp.detachLabel(user, projectName, labelId).url()) .withFormUrlEncodedBody(data) .withHeader("Accept", "application/json") .withSession(UserApp.SESSION_USERID, admin.id.toString())); // Then assertThat(status(result)).isEqualTo(204); assertThat(Project.findByOwnerAndProjectName("yobi", "projectYobi").labels.contains(label1)) .isFalse(); }
@Test public void projectOverviewUpdateTest() { // Given Project project = Project.findByOwnerAndProjectName("yobi", "projectYobi"); String newDescription = "new overview description"; ObjectNode requestJson = Json.newObject(); requestJson.put("overview", newDescription); User member = User.findByLoginId("yobi"); // When Result result = callAction( controllers.routes.ref.ProjectApp.projectOverviewUpdate("yobi", "projectYobi"), fakeRequest(PUT, "/yobi/projectYobi") .withJsonBody(requestJson) .withHeader("Accept", "application/json") .withHeader("Content-Type", "application/json") .withSession(UserApp.SESSION_USERID, member.id.toString())); // Then assertThat(status(result)).isEqualTo(200); // response status code assertThat(contentAsString(result)) .isEqualTo("{\"overview\":\"new overview description\"}"); // response json body project.refresh(); assertThat(project.overview).isEqualTo(newDescription); // is model updated }
@Before public void setup() { doortts = User.findByLoginId("doortts"); nori = User.findByLoginId("nori"); yobi = Project.findByOwnerAndProjectName("yobi", "projectYobi"); cubrid = Project.findByOwnerAndProjectName("doortts", "CUBRID"); }
public static void save(Project project) { System.out.println("---> " + project.isPersistent()); Logger.warn("Next warning is intended!"); project.save(); validation.keep(); show(project.id); }
@Test public void getProject() throws ConnectionException { Project project = dive.getProject("torvalds", "linux"); assertNotNull(project); assertTrue(project.getForks() > 0); assertTrue(project.getWatchers() > 0); }
public static void delete(Long project_id) { Project p = getActiveProject(); if (p == null) { notFound(); } p.delete(getLoggedin()); Application.homepage(); }
public static void withMap(String companyId) { Company company = Company.findById(companyId); Project project = new Project(); project.companies = new HashMap(); project.companies.put(company.name, company); project.create(); render("@show", project); }
@Override public void onPostReceive(ReceivePack receivePack, Collection<ReceiveCommand> commands) { synchronized (project) { project.refresh(); project.lastPushedDate = new Date(); project.save(); } }
public static void doEdit(Project project) { if (params.get("project.deadline") == "") { project.deadline = null; } project.save(getLoggedin()); flash.put("success", "Project Information has been saved"); dashboard(project.id); }
public static void savePermissions(Long project_id) { Project p = getActiveProject(); if (p == null) { error(400, "Bad Request"); } p.updatePermissions(params, getLoggedin()); flash.put("success", "Permissions for Members of the Project have been saved"); permissions(project_id); }
public static void project(Long id) { Project project = Project.findById(id); Long UID = Long.parseLong(Session.current().get("user_id")); User u = User.findById(UID); if (project.canBeSeenBy(u)) { render(project); } else { projects(); } }
public static void createproject(String projectname, String projectdescription) { if (projectname != null && projectdescription != null) { Long id = Long.parseLong(Session.current().get("user_id")); User u = User.findById(id); Project p = new Project(projectname, projectdescription, u); p.save(); projects(); } else { render(); } }
@Test public void delete() { // Given User member = User.find.byId(2L); Project project = Project.findByOwnerAndProjectName("yobi", "projectYobi"); RecentlyVisitedProjects.addNewVisitation(member, project); // When project.delete(); // Then assertThat(Project.findByOwnerAndProjectName("yobi", "projectYobi")).isNull(); }
@Test public void optimisticLockException() { Project project1 = Project.findByOwnerAndProjectName("yobi", "projectYobi"); Project project2 = Project.findByOwnerAndProjectName("yobi", "projectYobi"); issue = new Issue(); issue.setProject(project1); issue.setTitle("a"); issue.save(); issue = new Issue(); issue.setProject(project2); issue.setTitle("b"); issue.save(); }
@Test public void label() { // Given Map<String, String> data = new HashMap<>(); data.put("category", "OS"); data.put("name", "linux"); User admin = User.findByLoginId("admin"); String user = "******"; String projectName = "projectYobi"; // When Result result = callAction( controllers.routes.ref.ProjectApp.attachLabel(user, projectName), fakeRequest(POST, routes.ProjectApp.attachLabel(user, projectName).url()) .withFormUrlEncodedBody(data) .withHeader("Accept", "application/json") .withSession(UserApp.SESSION_USERID, admin.id.toString())); // Then assertThat(status(result)).isEqualTo(CREATED); Iterator<Map.Entry<String, JsonNode>> fields = Json.parse(contentAsString(result)).getFields(); Map.Entry<String, JsonNode> field = fields.next(); Label expected = new Label(field.getValue().get("category").asText(), field.getValue().get("name").asText()); expected.id = Long.valueOf(field.getKey()); assertThat(expected.category).isEqualTo("OS"); assertThat(expected.name).isEqualTo("linux"); assertThat(Project.findByOwnerAndProjectName("yobi", "projectYobi").labels.contains(expected)) .isTrue(); }
/** * Responds to a request to add an issue label category for the specified project. * * <p>Adds an issue label category created with values taken from {@link * Form#bindFromRequest(java.util.Map, String...)} in the project specified by the {@code * ownerName} and {@code projectName}. But if there has already been the same issue label category * in name, then this method returns an empty 204 No Content response. * * <p>When a new category is added, this method encodes the category's fields: {@link * IssueLabelCategory#id}, {@link IssueLabelCategory#name}, {@link * IssueLabelCategory#isExclusive}, and includes them in the body of the 201 Created response. But * if the client cannot accept {@code application/json}, it returns the 201 Created with no * response body. * * @param ownerName the name of a project owner * @param projectName the name of a project * @return the response to the request to add a new issue label category */ @IsCreatable(ResourceType.ISSUE_LABEL_CATEGORY) public static Result newCategory(String ownerName, String projectName) { Form<IssueLabelCategory> form = new Form<>(IssueLabelCategory.class).bindFromRequest(); if (form.hasErrors()) { return badRequest(); } IssueLabelCategory category = form.get(); category.project = Project.findByOwnerAndProjectName(ownerName, projectName); if (category.exists()) { return noContent(); } category.save(); if (!request().accepts("application/json")) { return created(); } Map<String, String> categoryPropertyMap = new HashMap<>(); categoryPropertyMap.put("id", "" + category.id); categoryPropertyMap.put("name", category.name); categoryPropertyMap.put("isExclusive", "" + category.isExclusive); return created(toJson(categoryPropertyMap)).as("application/json"); }
@IsAllowed(Operation.UPDATE) public static Result labelsForm(String ownerName, String projectName) { Project project = Project.findByOwnerAndProjectName(ownerName, projectName); List<IssueLabel> labels = IssueLabel.findByProject(project); return ok(views.html.project.issuelabels.render(project, labels)); }
/** * This is a Class Constructor Creates a new Product Role object with the basic product role * requirements * * @author Heba Elsherif * @param projectID id of the project of the product role * @param name name of the product role * @param description description of the product role * @return void */ public ProductRole(long projectId, String name, String description) { this.deleted = false; this.name = name; this.description = description; this.project = Project.findById(projectId); this.Tasks = new ArrayList<Task>(); }
@Test public void roleOf() { // GIVEN String loginId = "yobi"; Project project = Project.findByOwnerAndProjectName(loginId, "projectYobi"); // WHEN String roleName = ProjectUser.roleOf(loginId, project); // THEN assertThat(roleName).isEqualTo("manager"); // WHEN roleName = ProjectUser.roleOf("admin", project); // THEN assertThat(roleName).isEqualTo("sitemanager"); // WHEN roleName = ProjectUser.roleOf((String) null, project); // THEN assertThat(roleName).isEqualTo("anonymous"); // WHEN roleName = ProjectUser.roleOf("keesun", project); // THEN assertThat(roleName).isEqualTo("anonymous"); // WHEN roleName = ProjectUser.roleOf("laziel", project); // THEN assertThat(roleName).isEqualTo("member"); }
@Test public void testAcceptTransferWithWrongKey() throws IOException, ServletException, ClientException { // Given GitRepository.setRepoPrefix("resources/test/repo/git/"); Project project = Project.findByOwnerAndProjectName("yobi", "projectYobi"); RepositoryService.createRepository(project); User sender = User.findByLoginId("yobi"); User newOwner = User.findByLoginId("doortts"); ProjectTransfer pt = ProjectTransfer.requestNewTransfer(project, sender, newOwner.loginId); assertThat(pt.confirmKey).isNotNull(); // When Result result = callAction( controllers.routes.ref.ProjectApp.acceptTransfer(pt.id, "wrongKey"), fakeRequest(PUT, routes.ProjectApp.acceptTransfer(pt.id, "wrongKey").url()) .withSession(UserApp.SESSION_USERID, newOwner.id.toString())); // Then assertThat(status(result)).isEqualTo(400); support.Files.rm_rf(new File(GitRepository.getRepoPrefix())); }
private static void collectDatum( List<Project> projects, List<Posting> postings, List<Issue> issues, List<PullRequest> pullRequests, List<Milestone> milestones, int daysAgo) { // collect all postings, issues, pullrequests and milesotnes that are contained in the projects. for (Project project : projects) { if (AccessControl.isAllowed(UserApp.currentUser(), project.asResource(), Operation.READ)) { postings.addAll(Posting.findRecentlyCreatedByDaysAgo(project, daysAgo)); issues.addAll(Issue.findRecentlyOpendIssuesByDaysAgo(project, daysAgo)); pullRequests.addAll(PullRequest.findOpendPullRequestsByDaysAgo(project, daysAgo)); milestones.addAll(Milestone.findOpenMilestones(project.id)); } } }
private static Result labelsAsPjax(String ownerName, String projectName) { response().setHeader("Cache-Control", "no-cache, no-store"); Project project = Project.findByOwnerAndProjectName(ownerName, projectName); List<IssueLabel> labels = IssueLabel.findByProject(project); return ok(views.html.project.partial_issuelabels_list.render(project, labels)); }
public Result index(Integer projectid) { project = Project.find.byId(projectid); for (Task task : project.getTasks()) { if (folders.containsKey(task.getFolder())) folders.get(task.getFolder()).add(task); else folders.put(task.getFolder(), new ArrayList<Task>(Arrays.asList(task))); } return ok(this); }
/** * Shows the dashboard page. * * @param mode applicable to the nav bar * @return */ @Restrict(@Group(Application.USER_ROLE)) public Result dashboard(String mode) { final AuthUser currentAuthUser = PlayAuthenticate.getUser(session()); final User localUser = User.findByAuthUserIdentity(currentAuthUser); List<Project> projects = Project.findAllByUser(localUser.email); return ok(dashboard_main.render(localUser, Const.NAV_DASHBOARD, my_projects.render(projects))); }
public static void projects() { Long id = Long.parseLong(Session.current().get("user_id")); User u = User.findById(id); List<Project> projects = Project.find("owner = ?", u).fetch(); render(projects); }
private static List<Project> collectProjects(String loginId, User user, String[] groupNames) { List<Project> projectCollection = new ArrayList<>(); // collect all projects that are included in the project groups. for (String group : groupNames) { switch (group) { case "own": addProjectNotDupped(projectCollection, Project.findProjectsCreatedByUser(loginId, null)); break; case "member": addProjectNotDupped(projectCollection, Project.findProjectsJustMemberAndNotOwner(user)); break; case "watching": addProjectNotDupped(projectCollection, user.getWatchingProjects()); break; } } return projectCollection; }
/** * Checks if a certain product role name exists in a certain project . * * @author Heba Elsherif * @param name the name of a product role. * @param projectId the project id that the product role belongs to. * @return boolean value indecating if the product role name already exists or no. */ public static boolean hasUniqueName(String name, long projectId) { Project project = Project.findById(projectId); for (int i = 0; i < project.productRoles.size(); i++) { if (project.productRoles.get(i).name.equalsIgnoreCase(name) && !project.productRoles.get(i).deleted) { return false; } } return true; }
@Test public void memberCanSearchPublicProjectsAsJson() { // Given User member = User.find.byId(2L); Project project = Project.findByOwnerAndProjectName("yobi", "projectYobi"); // When // Then testProjectSearch(member, project, acceptJson, contains(project.owner + "/" + project.name)); }
@Test public void anonymousCanSearchPublicProjectsAsJson() { // Given User anonymous = User.anonymous; Project project = Project.findByOwnerAndProjectName("yobi", "projectYobi"); // When // Then testProjectSearch(anonymous, project, acceptJson, contains(project.owner + "/" + project.name)); }