@Restrict(UnitRole.DEFECTVIEW) public static void defectDetails(Long baseObjectId, String[] fields) { Defect defect = Lookups.getDefect(baseObjectId); if (defect == null) { Logger.error(Logger.LogType.TECHNICAL, "Could not find defect with ID %s", defect.id); notFound("Sorry, the selected defect could not be found. Please refresh the page"); } renderFields(defect, fields); }
@Test public void testLookup() { Lookup<IPriorityFoo> lookup = Lookups.getPriority(IPriorityFoo.class); // This should only be ImplB, which has the highest priority. IFoo myFoo = lookup.lookup(); LOG.info("Got foo implementation: " + myFoo.getClass().getName()); assertTrue(myFoo instanceof Providers.PriorityImplB); String result = myFoo.getMessage(); LOG.info("Got result string: " + result); assertEquals("priorityimplB", result); }
@Restrict(UnitRole.DEFECTDELETE) public static void deleteDefect(Long defectId) { Defect defect = Lookups.getDefect(defectId); if (defect == null) { Logger.error(Logger.LogType.TECHNICAL, "Could not find defect for deletion %s", defectId); notFound("Sorry, the selected defect could not be found. Please refresh the page"); } try { defect.delete(); } catch (Throwable t) { Logger.error(Logger.LogType.DB, "Error deleting defect %s", defectId); error( String.format( "An error occurred while deleting defect %s, please try again", defect.naturalId)); } ok(); }
@Test public void testMultiLookup() { Lookup<IPriorityFoo> lookup = Lookups.getPriority(IPriorityFoo.class); // We should get back a list of providers, ImplB followed by ImplA, // according to their priority order. List<IFoo> foos = new ArrayList<IFoo>(); for (IFoo foo : lookup) { foos.add(foo); } assertEquals("expected two implementations", 2, foos.size()); LOG.info("First impl class: " + foos.get(0).getClass().getName()); LOG.info("Second impl class: " + foos.get(1).getClass().getName()); assertTrue("expected implb first", foos.get(0) instanceof Providers.PriorityImplB); assertTrue("expected impla next", foos.get(1) instanceof Providers.PriorityImplA); }
@Restrict(UnitRole.DEFECTEDIT) public static void updateDefect(@Valid Defect defect) { Defect d = Lookups.getDefect(defect.getId()); if (d == null) { Logger.error(Logger.LogType.TECHNICAL, "Could not find defect with ID %s", defect.getId()); notFound("Sorry, the selected defect could not be found. Please refresh the page"); } d.name = defect.name; d.description = defect.description; d.assignedTo = defect.assignedTo; d.status = defect.status; try { d.save(); } catch (Throwable t) { Logger.error(Logger.LogType.DB, "Error updating defect"); error("An error occurred while saving the defect, please try again."); } ok(); }
@Restrict(UnitRole.DEFECTVIEW) public static void defectDescription(Long defectId) { Defect defect = Lookups.getDefect(defectId); if (defect == null) { Logger.error(Logger.LogType.TECHNICAL, "Could not find defect with ID %s", defectId); notFound("Sorry, the selected defect could not be found. Please refresh the page"); } JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("defectTitle", defect.name); jsonObject.addProperty( "defectAssignedTo", defect.assignedTo == null ? "" : defect.assignedTo.toString()); jsonObject.addProperty( "defectSubmittedBy", defect.submittedBy == null ? "" : defect.submittedBy.toString()); jsonObject.addProperty("defectStatus", defect.status == null ? "" : defect.status.toString()); jsonObject.addProperty( "defectCreated", defect.created == null ? "" : defect.created.toString()); jsonObject.addProperty("defectTags", defect.tags == null ? "" : defect.tags.toString()); jsonObject.addProperty( "defectDescription", defect.description == null ? "" : defect.description); renderJSON(jsonObject.toString()); }
@Restrict(UnitRole.DEFECTVIEW) public static void allTags(String q) { Lookups.allTags(getActiveProjectId(), Tag.TagType.DEFECT, q); }