示例#1
0
文件: Site.java 项目: nuxeo/lm-labs
  @POST
  @Path("@manage-sidebar")
  public Object manageSidebar() {
    FormData form = ctx.getForm();
    CoreSession session = getCoreSession();
    try {
      int nbRows = new Integer(form.getString("nbRows")).intValue();
      HtmlPage sidebar = site.getSidebar();
      HtmlSection section = sidebar.section(0);
      section.remove();
      sidebar.addSection();
      section = sidebar.section(0);
      HtmlRow row = null;
      String widget = "";
      for (int i = 0; i < nbRows; i++) {
        widget = form.getString("bloc" + i);
        if (!"html/editor".equals(widget)) {
          row = section.addRow();
          row.addContent(0, "");
          session.saveDocument(sidebar.getDocument());
          session.save();
          GadgetUtils.syncWidgetsConfig(row.content(0), widget, sidebar.getDocument(), session);
        }
      }
    } catch (Exception e) {
      throw WebException.wrap("Problème lors de la sauvegarde des widgets de la sidebar", e);
    }
    // TODO row's widget config

    return Response.ok().build();
  }
示例#2
0
文件: Site.java 项目: nuxeo/lm-labs
  @Path("@configWidget-sidebar")
  public Object configWidgetSidebar() {
    FormData form = ctx.getForm();
    try {
      int rowIdx = new Integer(form.getString("rowIdx")).intValue();
      HtmlPage sidebar = site.getSidebar();

      HtmlContent content = sidebar.section(0).row(rowIdx).content(0);
      Resource newObject = newObject("HtmlContent", sidebar.getDocument(), content);
      return newObject;
      /*List<LabsWidget> widgets = content.getGadgets(getCoreSession());
      if (!widgets.isEmpty()) {
          LabsWidget widget = widgets.get(0);
          if (WidgetType.OPENSOCIAL.equals(widget.getType())) {
              DocumentRef ref = ((LabsOpensocialGadget)widget).getDoc().getRef();
              if (getCoreSession().exists(ref)) {
                  DocumentModel gadgetDoc = getCoreSession().getDocument(ref);
                  return newObject("HtmlWidget", gadgetDoc, doc, content, widget);
              }
              return Response.noContent().build();
          }
          return newObject("HtmlWidget", null, doc, content, widget);
      }
      return Response.noContent().build();*/

    } catch (Exception e) {
      throw WebException.wrap(
          "Problème lors de la sauvegarde de la configuration du widget de la sidebar", e);
    }
  }
示例#3
0
 public Class<?> get() {
   if (clazz == null) {
     try {
       clazz = loader.loadClass(className);
     } catch (ReflectiveOperationException e) {
       throw WebException.wrap("Failed to load class " + className, e);
     }
   }
   return clazz;
 }
示例#4
0
  @POST
  public Response createNew(T artifact) {
    try {
      checkPrecondition(artifact);
      artifact = createArtifact(artifact);
      return Response.status(Status.CREATED).entity(artifact).build();

    } catch (NuxeoException e) {
      throw WebException.wrap(e);
    }
  }
 public static boolean isNotRejectedComment(DocumentModel document) {
   try {
     if (!LabsSiteConstants.CommentsState.REJECT
         .getState()
         .equals(document.getCurrentLifeCycleState())) {
       return true;
     }
     return false;
   } catch (ClientException e) {
     throw WebException.wrap(e);
   }
 }
 @GET
 @Path("/@activate")
 public Object doActivate() {
   try {
     AdministrativeStatusManager manager =
         Framework.getLocalService(AdministrativeStatusManager.class);
     manager.setNuxeoInstanceStatus(AdministrativeStatus.ACTIVE, "", ctx.getPrincipal().getName());
     return redirect(getPath());
   } catch (Exception e) {
     throw WebException.wrap(e);
   }
 }
示例#7
0
 @Path("{artName}")
 public Object getArtifactWebObject(@PathParam("artName") String artName) {
   try {
     T artifact = getArtifact(artName);
     if (artifact == null) {
       throw new WebResourceNotFoundException(getArtifactType() + " does not exist");
     }
     return newObject(getArtifactType(), artifact);
   } catch (NuxeoException e) {
     throw WebException.wrap(e);
   }
 }
示例#8
0
  @Path("group/{groupName}")
  public Object doGetUserToGroup(@PathParam("groupName") String groupName) {
    try {
      NuxeoGroup group = um.getGroup(groupName);
      if (group == null) {
        throw new WebResourceNotFoundException("Group not found");
      }

      return newObject("userToGroup", currentArtifact, group);
    } catch (ClientException e) {
      throw WebException.wrap(e);
    }
  }
示例#9
0
文件: Site.java 项目: nuxeo/lm-labs
 @Override
 public Object doGet() {
   try {
     return redirect(
         getPath()
             + '/'
             + URIUtils.quoteURIPathComponent(
                 (new org.nuxeo.common.utils.Path(
                             Tools.getAdapter(
                                     SiteDocument.class,
                                     site.getIndexDocument(),
                                     ctx.getCoreSession())
                                 .getResourcePath())
                         .removeFirstSegments(1))
                     .toString(),
                 false));
   } catch (HomePageException e) {
     throw WebException.wrap(e);
   } catch (ClientException e) {
     throw WebException.wrap(e);
   }
 }
 @PUT
 public Object doPut() {
   FormData form = ctx.getForm();
   try {
     AdministrativeStatusManager manager =
         Framework.getLocalService(AdministrativeStatusManager.class);
     manager.setNuxeoInstanceStatus(
         form.getString("status"), "assigned from rest interface", ctx.getPrincipal().getName());
     return redirect(getPath());
   } catch (Exception e) {
     throw WebException.wrap(e);
   }
 }
示例#11
0
  @Override
  public DirectoryEntry readFrom(
      Class<DirectoryEntry> type,
      Type genericType,
      Annotation[] annotations,
      MediaType mediaType,
      MultivaluedMap<String, String> httpHeaders,
      InputStream entityStream)
      throws IOException, WebApplicationException {
    String content = IOUtils.toString(entityStream);
    if (content.isEmpty()) {
      if (content.isEmpty()) {
        throw new WebException(
            "No content in request body", Response.Status.BAD_REQUEST.getStatusCode());
      }
    }

    try {
      return readRequest(content, httpHeaders);
    } catch (IOException | NuxeoException e) {
      throw WebException.wrap(e);
    }
  }
示例#12
0
文件: Site.java 项目: nuxeo/lm-labs
 private Response updateSite(FormData form) {
   String title = form.getString("dc:title");
   String url = form.getString("webc:url");
   String description = form.getString("dc:description");
   String piwikId = form.getString("piwik:piwikId");
   String siteTemplateStr = form.getString("labssite:siteTemplate");
   String category = form.getString("labssite:category");
   boolean modified = false;
   try {
     if (!StringUtils.isEmpty(title)) {
       site.setTitle(title);
       modified = true;
     }
     if (!StringUtils.isEmpty(description)) {
       site.setDescription(description);
       modified = true;
     }
     if (!StringUtils.isEmpty(category)) {
       site.setCategory(category);
       modified = true;
     }
     String oldUrl = site.getURL();
     url = StringUtils.trim(url);
     if (!StringUtils.isEmpty(url) && !url.equals(oldUrl)) {
       site.setURL(url);
       modified = true;
     }
     String oldPiwikId = site.getPiwikId();
     piwikId = StringUtils.trim(piwikId);
     if (!StringUtils.equals(piwikId, oldPiwikId)) {
       site.setPiwikId(piwikId);
       modified = true;
     }
     boolean isSiteTemplate = BooleanUtils.toBoolean(siteTemplateStr);
     if (site.isElementTemplate() != isSiteTemplate) {
       site.setElementTemplate(isSiteTemplate);
       modified = true;
     }
     if (isSiteTemplate) {
       if (form.isMultipartContent()) {
         Blob preview = form.getBlob("labssite:siteTemplatePreview");
         if (preview != null && !StringUtils.isEmpty(preview.getFilename())) {
           site.setElementPreview(preview);
           modified = true;
         }
       }
     } /* else {
           Blob siteTemplatePreview = null;
           try {
               siteTemplatePreview = site.getSiteTemplatePreview();
           } catch (ClientException e) {
               throw WebException.wrap(e);
           }
           if (siteTemplatePreview != null) {
               site.setElementPreview(null);
               modified = true;
           }
       }*/
     String msgLabel = "label.labssites.edit.noop";
     if (modified) {
       CoreSession session = ctx.getCoreSession();
       getSiteManager().updateSite(session, site);
       session.save();
       msgLabel = "label.labssites.edit.site.updated";
     }
     return redirect(
         ctx.getModulePath()
             + "/"
             + URIUtils.quoteURIPathComponent(site.getURL(), true)
             + "/@views/edit?message_success="
             + msgLabel);
   } catch (SiteManagerException e) {
     return redirect(getPath() + "/@views/edit?message_error=" + e.getMessage());
   } catch (ClientException e) {
     throw WebException.wrap(e);
   }
 }
 @Override
 public ExecutionRequest readFrom(
     Class<ExecutionRequest> arg0,
     Type arg1,
     Annotation[] arg2,
     MediaType arg3,
     MultivaluedMap<String, String> headers,
     InputStream in)
     throws IOException, WebApplicationException {
   ExecutionRequest req = null;
   try {
     List<String> ctypes = headers.get("Content-Type");
     String ctype = ctypes.get(0);
     // we need to copy first the stream into a file otherwise it may
     // happen that
     // javax.mail fail to receive some parts - I am not sure why -
     // perhaps the stream is no more available when javax.mail need it?
     File tmp = File.createTempFile("nx-automation-mp-upload-", ".tmp");
     FileUtils.copyToFile(in, tmp);
     // get the input from the saved file
     in = new SharedFileInputStream(tmp);
     try {
       MimeMultipart mp = new MimeMultipart(new InputStreamDataSource(in, ctype));
       BodyPart part = mp.getBodyPart(0); // use content ids
       InputStream pin = part.getInputStream();
       JsonParser jp = factory.createJsonParser(pin);
       req = JsonRequestReader.readRequest(jp, headers, getCoreSession());
       int cnt = mp.getCount();
       if (cnt == 2) { // a blob
         req.setInput(readBlob(request, mp.getBodyPart(1)));
       } else if (cnt > 2) { // a blob list
         BlobList blobs = new BlobList();
         for (int i = 1; i < cnt; i++) {
           blobs.add(readBlob(request, mp.getBodyPart(i)));
         }
         req.setInput(blobs);
       } else {
         log.error("Not all parts received.");
         for (int i = 0; i < cnt; i++) {
           log.error(
               "Received parts: "
                   + mp.getBodyPart(i).getHeader("Content-ID")[0]
                   + " -> "
                   + mp.getBodyPart(i).getContentType());
         }
         throw WebException.newException(
             new IllegalStateException("Received only " + cnt + " part in a multipart request"));
       }
     } finally {
       try {
         in.close();
       } catch (IOException e) {
         // do nothing
       }
       tmp.delete();
     }
   } catch (MessagingException | IOException e) {
     throw WebException.newException("Failed to parse multipart request", e);
   }
   return req;
 }