예제 #1
0
 /**
  * A real node-function (using the node argument). Returns the next newer node of same type. Also
  * a nice example on the difference between core and bridge.
  */
 public Object successor() {
   if (node == null) throw new IllegalArgumentException("successor is a node-function");
   if (cloud != null) {
     log.debug("Using bridge (security restrictions will be honoured)");
     NodeManager nm = node.getNodeManager();
     NodeQuery q = nm.createQuery();
     StepField field = q.getStepField(nm.getField("number"));
     q.setConstraint(
         q.createConstraint(
             field, FieldCompareConstraint.GREATER, Integer.valueOf(node.getNumber())));
     q.addSortOrder(field, SortOrder.ORDER_ASCENDING);
     q.setMaxNumber(1);
     NodeIterator i = nm.getList(q).nodeIterator();
     return i.hasNext() ? i.nextNode() : null;
   } else {
     log.debug("Using core.");
     throw new UnsupportedOperationException("Core implementation was dropped. See source code.");
     /* This is how it would go with core objects
     MMObjectBuilder builder = MMBase.getMMBase().getBuilder(node.getNodeManager().getName());
     NodeSearchQuery query = new NodeSearchQuery(builder);
     StepField field = query.getField(builder.getField("number"));
     BasicFieldValueConstraint cons = new BasicFieldValueConstraint(field, node.getNumber());
     cons.setOperator(FieldCompareConstraint.GREATER);
     query.setConstraint(cons);
     query.addSortOrder(field);
     query.setMaxNumber(1);
     try {
         java.util.Iterator<MMObjectNode> i = builder.getNodes(query).iterator();
         return i.hasNext() ?  i.next() : null;
     } catch (Exception e) {
         return null;
     }
     */
   }
 }
예제 #2
0
 protected String getProperty(Node node, String key) {
   NodeManager properties = node.getCloud().getNodeManager("properties");
   Function get = properties.getFunction("get");
   Parameters params = get.createParameters();
   params.set("node", node);
   params.set("key", key);
   return (String) get.getFunctionValue(params);
 }
예제 #3
0
 protected void setProperty(Node node, String key, String value) {
   NodeManager properties = node.getCloud().getNodeManager("properties");
   Function set = properties.getFunction("set");
   Parameters params = set.createParameters();
   params.set("node", node);
   params.set("key", key);
   if (value.length() > 255) {
     value = value.substring(0, 255);
   }
   params.set("value", value);
   set.getFunctionValue(params);
 }
예제 #4
0
  private Boolean sendMail(HttpServletRequest req, Node node, String email) {
    boolean send = false;

    Cloud cloud = node.getCloud();
    String emailbuilder = "email";
    try {
      Module sendmail = cloud.getCloudContext().getModule("sendmail");
      emailbuilder = sendmail.getProperty("emailbuilder");
    } catch (NotFoundException nfe) {
      log.warn("No email module " + nfe);
    }

    if (cloud.hasNodeManager(emailbuilder)) {

      NodeManager nm = cloud.getNodeManager(emailbuilder);
      Node message = nm.createNode();

      String host = req.getHeader("host");
      if (host == null || "".equals(host)) {
        try {
          host = java.net.InetAddress.getLocalHost().getHostName();
        } catch (UnknownHostException uhe) {
          log.warn("No host: " + uhe);
        }
      }
      String from = "downloader@" + host;
      // do a quick check if we've got something more or less valid
      Pattern p = Pattern.compile(".+@.+\\.[a-z]+");
      Matcher m = p.matcher(from);
      if (!m.matches()) {
        from = "*****@*****.**";
      }

      String mediaTitle = node.getStringValue("title");
      String mediaUrl = getProperty(node, URL_KEY);
      StringBuilder body = new StringBuilder();

      body.append("*This is an automated message / Dit is een geautomatiseerd bericht*");
      body.append("\n\n*English*");
      body.append("\n\nDear,");
      body.append("\n\nWe have received your file belonging to media item titled '")
          .append(mediaTitle)
          .append("'. ");
      body.append("In about 1 hour, you can find your submission at: ");
      body.append("http://").append(host).append("/media/").append(node.getNumber());
      body.append("\n\nKind regards,");
      body.append("\n\n").append(host);

      body.append("\n\n\n*Nederlands*");
      body.append("\n\nBeste,");
      body.append("\n\nWe hebben je bestand voor het media item met de titel '")
          .append(mediaTitle)
          .append("' ontvangen. ");
      body.append("Je kunt je bijdrage hier over circa een uur terugvinden: ");
      body.append("http://").append(host).append("/media/").append(node.getNumber());
      body.append("\n\nMet vriendelijke groet,");
      body.append("\n\n").append(host);

      message.setValue("from", from);
      message.setValue("to", email);
      message.setValue("subject", "Download complete / Download voltooid");
      message.setValue("body", body.toString());
      message.commit();

      Function mail = message.getFunction("mail");
      Parameters mail_params = mail.createParameters();
      mail_params.set("type", "oneshot");
      mail.getFunctionValue(mail_params);

      if (log.isDebugEnabled()) {
        log.debug("Message download ready send to: " + email);
      }
      send = true;
    } else {
      log.warn("Can not send message - no emailbuilder installed.");
    }

    return send;
  }