@Test public void doAction() throws PersistenceException { action.doAction(resource); verify(tagManager, times(1)).setTags(resource, new Tag[] {tag2, tag1}); }
@Override public String doAction(Resource resource) throws PersistenceException { Page page = context.getPageManager().getContainingPage(resource); if (page == null) { return "Unable to find a page for resource " + resource.getPath(); } Tag[] oldTags = page.getTags(); List<Tag> tagsToAdd = getTagsToAdd(oldTags); if (tagsToAdd.isEmpty()) { return "No missing tags to add"; } String successMessage = "Added page tags on " + page.getPath() + ": " + getTagListAsString(tagsToAdd); if (context.isDryRun()) { return successMessage; } TagManager tagManager = context.getTagManager(); List<Tag> tagsToSet = new ArrayList<>(tagsToAdd); tagsToSet.addAll(Arrays.asList(oldTags)); tagManager.setTags(page.getContentResource(), tagsToSet.toArray(new Tag[tagsToSet.size()])); return successMessage; }
AddPageTagsAction implements Action { @Override public String doAction(Resource resource) throws PersistenceException { Page page = context.getPageManager().getContainingPage(resource); if (page == null) { return "Unable to find a page for resource " + resource.getPath(); } Tag[] oldTags = page.getTags(); List<Tag> tagsToAdd = getTagsToAdd(oldTags); if (tagsToAdd.isEmpty()) { return "No missing tags to add"; } String successMessage = "Added page tags on " + page.getPath() + ": " + getTagListAsString(tagsToAdd); if (context.isDryRun()) { return successMessage; } TagManager tagManager = context.getTagManager(); List<Tag> tagsToSet = new ArrayList<>(tagsToAdd); tagsToSet.addAll(Arrays.asList(oldTags)); tagManager.setTags(page.getContentResource(), tagsToSet.toArray(new Tag[tagsToSet.size()])); return successMessage; } }
AddPageTagsAction implements Action { @Override public String doAction(Resource resource) throws PersistenceException { Page page = context.getPageManager().getContainingPage(resource); if (page == null) { return "Unable to find a page for resource " + resource.getPath(); } Tag[] oldTags = page.getTags(); List<Tag> tagsToAdd = getTagsToAdd(oldTags); if (tagsToAdd.isEmpty()) { return "No missing tags to add"; } String successMessage = "Added page tags on " + page.getPath() + ": " + getTagListAsString(tagsToAdd); if (context.isDryRun()) { return successMessage; } TagManager tagManager = context.getTagManager(); List<Tag> tagsToSet = new ArrayList<>(tagsToAdd); tagsToSet.addAll(Arrays.asList(oldTags)); tagManager.setTags(page.getContentResource(), tagsToSet.toArray(new Tag[tagsToSet.size()])); return successMessage; } AddPageTagsAction(BindingContext context, String... tags); }
AddPageTagsAction implements Action { @Override public String doAction(Resource resource) throws PersistenceException { Page page = context.getPageManager().getContainingPage(resource); if (page == null) { return "Unable to find a page for resource " + resource.getPath(); } Tag[] oldTags = page.getTags(); List<Tag> tagsToAdd = getTagsToAdd(oldTags); if (tagsToAdd.isEmpty()) { return "No missing tags to add"; } String successMessage = "Added page tags on " + page.getPath() + ": " + getTagListAsString(tagsToAdd); if (context.isDryRun()) { return successMessage; } TagManager tagManager = context.getTagManager(); List<Tag> tagsToSet = new ArrayList<>(tagsToAdd); tagsToSet.addAll(Arrays.asList(oldTags)); tagManager.setTags(page.getContentResource(), tagsToSet.toArray(new Tag[tagsToSet.size()])); return successMessage; } AddPageTagsAction(BindingContext context, String... tags); @Override String doAction(Resource resource); }
AddPageTagsAction implements Action { @Override public String doAction(Resource resource) throws PersistenceException { Page page = context.getPageManager().getContainingPage(resource); if (page == null) { return "Unable to find a page for resource " + resource.getPath(); } Tag[] oldTags = page.getTags(); List<Tag> tagsToAdd = getTagsToAdd(oldTags); if (tagsToAdd.isEmpty()) { return "No missing tags to add"; } String successMessage = "Added page tags on " + page.getPath() + ": " + getTagListAsString(tagsToAdd); if (context.isDryRun()) { return successMessage; } TagManager tagManager = context.getTagManager(); List<Tag> tagsToSet = new ArrayList<>(tagsToAdd); tagsToSet.addAll(Arrays.asList(oldTags)); tagManager.setTags(page.getContentResource(), tagsToSet.toArray(new Tag[tagsToSet.size()])); return successMessage; } AddPageTagsAction(BindingContext context, String... tags); @Override String doAction(Resource resource);  }