Ejemplo n.º 1
0
 @Override
 public List<String> getTags(CallingContext context, String raptureURIString) {
   RaptureURI internalURI = new RaptureURI(raptureURIString, Scheme.DOCUMENT);
   checkParameter(NAME, internalURI.getDocPath());
   Repository repository = getKernel().getRepo(internalURI.getFullPath()); // $NON-NLS-1$
   return repository.getTags();
 }
Ejemplo n.º 2
0
  @Override
  public void pullRemote(CallingContext context, String raptureURIString) {
    RaptureURI internalURI = new RaptureURI(raptureURIString, Scheme.DOCUMENT);
    if (internalURI.hasDocPath()) {
      throw RaptureExceptionFactory.create(
          HttpURLConnection.HTTP_BAD_REQUEST,
          apiMessageCatalog.getMessage("NoDocPath", internalURI.toShortString())); // $NON-NLS-1$
    }
    checkParameter(NAME, internalURI.getDocPath());

    log.info(
        Messages.getString("Admin.PullPerspective")
            + Messages.getString("Admin.OnType")
            + internalURI.getDocPath() // $NON-NLS-1$ //$NON-NLS-2$
            + Messages.getString("Admin.InAuthority")
            + internalURI.getAuthority()); // $NON-NLS-1$
    // NOW this is the fun one
    // Here are the steps
    // (1) Look at the local, does it have a remote defined? If
    // so, what is the latest commit known about
    // for that remote?
    // (2) Make a remote call to retrieve the commits up to that commit from
    // the RemoteLink
    // (3) For each commit, look at all of the references, retrieve them
    // from the remote and persist them
    // into the repo.
    // (4) Update the local perspective to point at the latest commit, and
    // update the Remote commit to point at that.

    getKernel().getRepo(internalURI.getFullPath()); // $NON-NLS-1$
  }
Ejemplo n.º 3
0
  @Override
  public List<AuditLogEntry> getRecentEntries(int count) {
    String docPath = blobPrefix;
    RaptureURI uri = RaptureURI.builder(Scheme.BLOB, blobUri).docPath(docPath).build();
    CallingContext context = ContextFactory.getKernelUser();
    BlobApiImpl blobApi = Kernel.getBlob().getTrusted();

    ArrayList<AuditLogEntry> ret = new ArrayList<AuditLogEntry>();
    BlobContainer content = blobApi.getBlob(context, uri.toString());
    if (content != null) {
      addContentToList(content, ret);
      return (ret.size() > count) ? ret.subList(ret.size() - count, ret.size()) : ret;
    } else {
      // get children blobs, eg. get logs for all steps of a work order
      Map<String, RaptureFolderInfo> childrenMap =
          blobApi.listBlobsByUriPrefix(context, uri.toString(), 1);

      if (childrenMap != null) {
        for (RaptureFolderInfo child : childrenMap.values()) {
          if (child.isFolder()) {
            continue;
          }
          String childUri = uri.getFullPath() + "/" + child.getName();
          content = blobApi.getBlob(context, childUri);
          addContentToList(content, ret, true);
          if (ret.size() >= count) {
            break;
          }
        }
      }
    }
    // sort audit log entries by time
    Collections.sort(
        ret,
        new Comparator<AuditLogEntry>() {
          @Override
          public int compare(AuditLogEntry o1, AuditLogEntry o2) {
            return o1.getWhen().compareTo(o2.getWhen());
          }
        });
    return (ret.size() > count) ? ret.subList(0, count) : ret;
  }
Ejemplo n.º 4
0
  private void process(
      Map<String, String> parameterMap, HttpServletRequest req, HttpServletResponse resp)
      throws IOException {
    logger.debug("req is " + req);
    logger.debug("resp is " + resp);
    logger.debug("parameterMap is " + parameterMap);

    // check script exists
    RaptureURI scriptURI = getScriptURI(req);
    logger.info(String.format("Running script for uri %s", scriptURI.toString()));
    RaptureScript script = Kernel.getScript().getScript(ContextFactory.ADMIN, scriptURI.toString());
    if (script == null || StringUtils.isBlank(script.getScript())) {
      logger.warn("Could not locate script for uri - " + scriptURI.toString());
      resp.setStatus(HttpStatus.SC_NOT_FOUND);
      return;
    }
    // run JavaScript
    try {
      CallingContext context = BaseDispatcher.validateSession(req);
      if (context != null) {
        logger.trace("Got session context " + context.debug());
        String result =
            Kernel.getScript().runScript(context, scriptURI.getFullPath(), parameterMap);
        resp.setCharacterEncoding("UTF-8");
        resp.getWriter().append(result);
        resp.setContentType("text/plain");
      } else {
        String err =
            "Cannot execute script " + script + " : cannot get session context for authorization";
        logger.error(err);
        resp.sendError(HttpURLConnection.HTTP_UNAUTHORIZED, err);
      }
    } catch (RaptNotLoggedInException re) {
      logger.error("Cannot execute script " + script + " : " + re.getMessage());
      resp.sendError(re.getStatus(), re.getMessage());
    }
  }