public TrainingProductImpl(Resource resource) {
    super(resource);

    resourceResolver = resource.getResourceResolver();
    pageManager = resourceResolver.adaptTo(PageManager.class);
    productPage = pageManager.getContainingPage(resource);
  }
  @Test
  public void testManyReferenceToSinglePages() throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();
    String path = "/content/geometrixx/en";
    String path1 = "/content/geometrixx/en";
    map.put("path", path);
    map.put("path1", path1);
    ValueMap vm = new ValueMapDecorator(map);
    when(resource.getValueMap()).thenReturn(vm);
    when(resource.getResourceResolver()).thenReturn(resolver);
    when(resolver.getResource(path)).thenReturn(res);
    when(resolver.getResource(path1)).thenReturn(res1);
    when(res.adaptTo(Page.class)).thenReturn(referredpage);
    when(res1.adaptTo(Page.class)).thenReturn(referredpage);
    when(referredpage.getName()).thenReturn("geometrixx");
    when(referredpage1.getName()).thenReturn("geometrixx");
    when(referredpage1.getPath()).thenReturn(path1);
    when(manager.getContainingPage(path1)).thenReturn(referredpage1);
    Calendar cal = GregorianCalendar.getInstance();
    when(referredpage.getLastModified()).thenReturn(cal);
    when(referredpage1.getLastModified()).thenReturn(cal);
    List<Reference> actual = instance.findReferences(resource);

    assertNotNull(actual);
    assertEquals(1, actual.size());
    assertEquals("geometrixx (Page)", actual.get(0).getName());
  }
Example #3
0
  public HtmlResponse performCommand(
      WCMCommandContext ctx,
      SlingHttpServletRequest request,
      SlingHttpServletResponse response,
      PageManager pageManager) {
    try {
      Page master = null;
      String srcPath = request.getParameter(WCMCommand.SRC_PATH_PARAM);
      if (StringUtils.isNotEmpty(srcPath)) {
        if (srcPath.endsWith("/jcr:content")) {
          srcPath = srcPath.substring(0, srcPath.length() - "/jcr:content".length());
        }
        master = pageManager.getPage(srcPath);
      }
      if (master == null) {
        return HtmlStatusResponseHelper.createStatusResponse(
            false, I18n.get(request, "Blueprint {0} not found.", "", srcPath));
      }

      boolean reset = "true".equals(request.getParameter(WCMCommand.FORCE_PARAM));

      String[] targets = request.getParameterValues(WCMCommand.DEST_PATH_PARAM);
      if (targets.length == 0) {
        return HtmlStatusResponseHelper.createStatusResponse(
            false, I18n.get(request, "No targets selected."));
      }

      int successCount = 0;
      int errorCount = 0;
      for (String target : targets) {
        try {
          Page targetPage = pageManager.getContainingPage(target);
          catalogGenerator.rolloutChanges(master, targetPage, reset);
          successCount++;
        } catch (Exception e) {
          log.error("Rollout failed for {}.", target, e);
          errorCount++;
        }
      }

      List<String> messages = new ArrayList<String>();
      messages.add(I18n.get(request, "Rollout Complete.  "));
      if (successCount > 0) {
        messages.add(I18n.get(request, "Rolled out changes to {0} catalogs.", "", successCount));
      }
      if (errorCount > 0) {
        messages.add(I18n.get(request, "Errors encountered in {0} catalogs.", "", errorCount));
      }
      return HtmlStatusResponseHelper.createStatusResponse(
          successCount > 0, messages.toArray(new String[messages.size()]), targets);
    } catch (Exception e) {
      String msg = I18n.get(request, "Error during rollout.");
      log.error(msg, e);
      return HtmlStatusResponseHelper.createStatusResponse(false, msg);
    }
  }
 @Before
 public void setUp() throws Exception {
   Map<String, Object> map = new HashMap<String, Object>();
   String path = "/content/geometrixx/en";
   map.put("path", path);
   ValueMap vm = new ValueMapDecorator(map);
   when(resource.getValueMap()).thenReturn(vm);
   when(resource.getResourceResolver()).thenReturn(resolver);
   when(resolver.adaptTo(PageManager.class)).thenReturn(manager);
   when(manager.getContainingPage(path)).thenReturn(referredpage);
   when(referredpage.getPath()).thenReturn(path);
   when(resource.listChildren()).thenReturn(iter);
   when(iter.hasNext()).thenReturn(false);
   when(resolver.getResource(path)).thenReturn(res);
   when(res.adaptTo(Page.class)).thenReturn(referredpage);
   when(referredpage.getName()).thenReturn("geometrixx");
   Calendar cal = GregorianCalendar.getInstance();
   when(referredpage.getLastModified()).thenReturn(cal);
 }
  @Test
  public void testMultipleReferencesReferenceToPages() throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();
    String path = "\"/content/geometrixx/en\",\"/content/geometrixx/en/toolbar\"";
    String path1 = "/content/geometrixx/en/toolbar";
    map.put("path", path);
    // map.put("path1", path1);
    ValueMap vm = new ValueMapDecorator(map);
    when(resource.getValueMap()).thenReturn(vm);
    when(resource.getResourceResolver()).thenReturn(resolver);
    when(resolver.getResource(path)).thenReturn(res);
    when(resolver.getResource(path1)).thenReturn(res1);
    when(res.adaptTo(Page.class)).thenReturn(referredpage);
    when(res1.adaptTo(Page.class)).thenReturn(referredpage1);
    when(referredpage.getName()).thenReturn("geometrixx");
    when(referredpage1.getName()).thenReturn("geometrixx1");
    when(referredpage1.getPath()).thenReturn(path1);
    when(manager.getContainingPage(path1)).thenReturn(referredpage1);
    Calendar cal = GregorianCalendar.getInstance();
    when(referredpage.getLastModified()).thenReturn(cal);
    when(referredpage1.getLastModified()).thenReturn(cal);
    List<Reference> actual = instance.findReferences(resource);

    assertNotNull(actual);
    assertEquals(2, actual.size());

    boolean geometrixxFound = false;
    boolean geometrixxOneFound = false;
    for (Reference ref : actual) {
      if (ref.getName().equals("geometrixx (Page)")) {
        geometrixxFound = true;
      } else if (ref.getName().equals("geometrixx1 (Page)")) {
        geometrixxOneFound = true;
      }
    }

    assertTrue(geometrixxFound);
    assertTrue(geometrixxOneFound);
  }
 /**
  * Returns Locale on the basis of Current page.
  *
  * @param resource the Resource
  * @return Locale
  */
 public static Locale getLocaleFromPage(final Resource resource) {
   final PageManager pageManager = resource.getResourceResolver().adaptTo(PageManager.class);
   final Page currentPage = pageManager.getContainingPage(resource);
   return currentPage.getLanguage(false);
 }