private String siteFavouritedKey(SiteInfo siteInfo) {
    PrefKeys prefKeys = getPrefKeys(Type.SITE);

    StringBuilder sitePrefKeyBuilder = new StringBuilder(prefKeys.getSharePrefKey());
    sitePrefKeyBuilder.append(siteInfo.getShortName());
    String sitePrefKey = sitePrefKeyBuilder.toString();

    String favouritedKey = sitePrefKey;
    return favouritedKey;
  }
  private String siteCreatedAtKey(SiteInfo siteInfo) {
    PrefKeys prefKeys = getPrefKeys(Type.SITE);

    StringBuilder sitePrefKeyBuilder = new StringBuilder(prefKeys.getAlfrescoPrefKey());
    sitePrefKeyBuilder.append(siteInfo.getShortName());
    String sitePrefKey = sitePrefKeyBuilder.toString();

    StringBuilder createdAtKeyBuilder = new StringBuilder(sitePrefKey);
    createdAtKeyBuilder.append(".createdAt");
    String createdAtKey = createdAtKeyBuilder.toString();
    return createdAtKey;
  }
Example #3
0
  private String getSiteName(Map<String, String> properties) {
    String siteFullName = properties.get(wfVarResourceName);
    SiteInfo site = siteService.getSite(siteFullName);
    if (site == null)
      throw new InvitationException("The site " + siteFullName + " could not be found.");

    String siteName = site.getShortName();
    String siteTitle = site.getTitle();
    if (siteTitle != null && siteTitle.length() > 0) {
      siteName = siteTitle;
    }
    return siteName;
  }
Example #4
0
  public void testRenamePageWithEmptyTitle() throws Exception {
    JSONObject page;
    String name = System.currentTimeMillis() + "";
    String name2 = System.currentTimeMillis() + 1 + "";

    // Create a page
    page = createOrUpdatePage(name, name, null, Status.STATUS_OK);
    assertEquals("Incorrect JSON: " + page.toString(), true, page.has("title"));

    // Fetch it and check
    page = getPage(name, Status.STATUS_OK);
    assertEquals(name, page.getString("name"));
    assertEquals(name, page.getString("title"));

    // update title
    SiteInfo site = siteService.getSite(SITE_SHORT_NAME_WIKI);
    WikiPageInfo pageInfo = wikiService.getWikiPage(site.getShortName(), name);
    NodeRef pageRef = pageInfo.getNodeRef();
    nodeService.setProperty(pageRef, ContentModel.PROP_TITLE, "");

    // Fetch it and check
    page = getPage(name, Status.STATUS_OK);
    JSONArray versions = page.getJSONArray("versionhistory");

    int maxVersionIndex = versions.length() - 1;
    double vNum = Double.parseDouble(versions.getJSONObject(maxVersionIndex).getString("version"));
    String newTitle = versions.getJSONObject(maxVersionIndex).getString("title");
    for (int i = versions.length() - 2; i >= 0; i--) {
      JSONObject version = versions.getJSONObject(i);
      String ver = version.getString("version");
      if (Double.parseDouble(ver) > vNum) {
        maxVersionIndex = i;
        vNum = Double.parseDouble(ver);
        newTitle = versions.getJSONObject(maxVersionIndex).getString("title");
      }
    }
    assertEquals(name, page.getString("name"));
    assertEquals("", newTitle);

    renamePage(name, name2, Status.STATUS_OK);

    // Fetch it at the new address
    page = getPage(name2, Status.STATUS_OK);
    assertEquals(name2, page.getString("name"));
    assertEquals(name2, page.getString("title"));
  }
  private boolean removeFavouriteSite(String userName, NodeRef nodeRef) {
    PrefKeys prefKeys = getPrefKeys(Type.SITE);
    boolean exists = false;

    SiteInfo siteInfo = siteService.getSite(nodeRef);
    if (siteInfo != null) {
      StringBuilder sitePrefKeyBuilder = new StringBuilder(prefKeys.getSharePrefKey());
      sitePrefKeyBuilder.append(siteInfo.getShortName());
      String sitePrefKey = sitePrefKeyBuilder.toString();

      String siteFavouritedKey = siteFavouritedKey(siteInfo);

      exists = preferenceService.getPreference(userName, siteFavouritedKey) != null;
      preferenceService.clearPreferences(userName, sitePrefKey);
    } else {
      throw new IllegalArgumentException("NodeRef " + nodeRef + " is not a site");
    }

    return exists;
  }
Example #6
0
  @Override
  protected Map<String, Object> executeImpl(
      SiteInfo site,
      String linkName,
      WebScriptRequest req,
      JSONObject json,
      Status status,
      Cache cache) {
    Map<String, Object> model = new HashMap<String, Object>();

    // Try to find the link
    LinkInfo link = linksService.getLink(site.getShortName(), linkName);
    if (link == null) {
      String message = "No link found with that name";

      status.setCode(Status.STATUS_NOT_FOUND);
      status.setMessage(message);
      model.put(PARAM_MESSAGE, message);
      return model;
    }

    // Get the new link details from the JSON
    // Update the main properties
    link.setTitle(getOrNull(json, "title"));
    link.setDescription(getOrNull(json, "description"));
    link.setURL(getOrNull(json, "url"));

    // Handle internal / not internal
    if (json.containsKey("internal")) {
      link.setInternal(true);
    } else {
      link.setInternal(false);
    }

    // Do the tags
    link.getTags().clear();
    List<String> tags = getTags(json);
    if (tags != null && tags.size() > 0) {
      link.getTags().addAll(tags);
    }

    // Update the link
    try {
      link = linksService.updateLink(link);
    } catch (AccessDeniedException e) {
      String message = "You don't have permission to update that link";

      status.setCode(Status.STATUS_FORBIDDEN);
      status.setMessage(message);
      model.put(PARAM_MESSAGE, message);
      return model;
    }

    // Generate an activity for the change
    addActivityEntry("updated", link, site, req, json);

    // Build the model
    model.put(PARAM_MESSAGE, "Node " + link.getNodeRef() + " updated");
    model.put("link", link);
    model.put("site", site);
    model.put("siteId", site.getShortName());

    // All done
    return model;
  }
  @Override
  protected Map<String, Object> executeImpl(
      SiteInfo site,
      String pageTitle,
      WebScriptRequest req,
      JSONObject json,
      Status status,
      Cache cache) {
    Map<String, Object> model = new HashMap<>();

    // Grab the version string
    Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
    String versionId = templateVars.get("versionId");
    if (versionId == null) {
      String error = "No versionId supplied";
      throw new WebScriptException(Status.STATUS_BAD_REQUEST, error);
    }

    // Try to find the page
    WikiPageInfo page = wikiService.getWikiPage(site.getShortName(), pageTitle);
    if (page == null) {
      String message = "The Wiki Page could not be found";
      status.setCode(Status.STATUS_NOT_FOUND);
      status.setMessage(message);

      // Return an empty string though
      model.put(PARAM_CONTENT, "");
      return model;
    }

    // Fetch the version history for the node
    VersionHistory versionHistory = null;
    Version version = null;
    try {
      versionHistory = versionService.getVersionHistory(page.getNodeRef());
    } catch (AspectMissingException e) {
    }

    if (versionHistory == null) {
      // Not been versioned, return an empty string
      model.put(PARAM_CONTENT, "");
      return model;
    }

    // Fetch the version by either ID or Label
    Matcher m = LABEL_PATTERN.matcher(versionId);
    if (m.matches()) {
      // It's a version label like 2.3
      try {
        version = versionHistory.getVersion(versionId);
      } catch (VersionDoesNotExistException e) {
      }
    } else {
      // It's a version ID like ed00bac1-f0da-4042-8598-45a0d39cb74d
      // (The ID is usually part of the NodeRef of the frozen node, but we
      //  don't assume to be able to just generate the full NodeRef)
      for (Version v : versionHistory.getAllVersions()) {
        if (v.getFrozenStateNodeRef().getId().equals(versionId)) {
          version = v;
        }
      }
    }

    // Did we find the right version in the end?
    String contents;
    if (version != null) {
      ContentReader reader =
          contentService.getReader(version.getFrozenStateNodeRef(), ContentModel.PROP_CONTENT);
      if (reader != null) {
        contents = reader.getContentString();
      } else {
        // No content was stored in the version history
        contents = "";
      }
    } else {
      // No warning of the missing version, just return an empty string
      contents = "";
    }

    // All done
    model.put(PARAM_CONTENT, contents);
    model.put("page", page);
    model.put("site", site);
    model.put("siteId", site.getShortName());
    return model;
  }
  public List<TopItem> listTopItems(int count, String type, int date, SiteInfo site) {

    ActivityScoreQuery activityScoreQuery = new ActivityScoreQuery();

    TopQuery topQuery = activityScoreQuery;

    // Site
    topQuery.setSite(site.getShortName());

    // Date
    DateMidnight dm = new DateMidnight();
    dm = dm.minusDays(date);
    topQuery.setDate(dm.toDate());

    // Criteria
    Map<String, TopCriterion> activityCriterionMap = typeActivityCriteriaMap.get(type);
    if (activityCriterionMap == null) {
      throw new IllegalArgumentException("Unknown top type '" + type + "'");
    }
    List<TopCriterion> criteria = new ArrayList<TopCriterion>(activityCriterionMap.values());

    topQuery.setCriteria(criteria);

    List<UserScore> topResults = topActivityDAO.executeTopQuery(topQuery);

    int topSize = Math.min(topResults.size(), count);
    List<TopItem> topItems = new ArrayList<TopItem>(topSize);

    if (topSize > 0) {

      Map<String, TopItem> topItemsMap = new HashMap<String, TopItem>(topSize);
      List<String> userIds = new ArrayList<String>(topSize);
      int position = 1;
      for (UserScore topUser : topResults) {

        String userName = topUser.getUserId();

        NodeRef node = personService.getPerson(userName);

        int score = topUser.getScore();

        TopItem topItem = new TopItem(position, score, node);
        topItems.add(topItem);

        topItemsMap.put(userName, topItem);

        userIds.add(userName);

        position++;

        if (position > count) {
          break;
        }
      }

      activityScoreQuery.setUserIds(userIds);

      List<UserActivityScore> activityScoreResults =
          topActivityDAO.executeActivityScoreQuery(activityScoreQuery);

      for (UserActivityScore userActivityScore : activityScoreResults) {

        String activity = userActivityScore.getActivity();
        TopCriterion criterion = activityCriterionMap.get(activity);
        userActivityScore.setCriterion(criterion);

        String userName = userActivityScore.getUserId();
        TopItem topItem = topItemsMap.get(userName);
        Score score = topItem.getScore();
        score.getCriterionScores().add(userActivityScore);
      }
    }

    if (logger.isDebugEnabled()) {
      XStream xstream = new XStream();
      logger.debug("listTopItems()=" + xstream.toXML(topItems));
    }

    return topItems;
  }