@Test
  public void testToXmlDate() throws Exception {
    Calendar cal = Calendar.getInstance();
    cal.set(2014, Calendar.DECEMBER, 15, 0, 0, 0);
    cal.set(Calendar.MILLISECOND, 0);

    XMLGregorianCalendar actual = DocumentUtils.toXmlDate(cal.getTime());

    assertEquals("2014-12-15", actual.toXMLFormat());
  }
Beispiel #2
0
  /** Upload an encoded Base64 file to the repository and decode it back once it's uploaded. */
  @Override
  protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    HashMap<String, Object> model = new HashMap<String, Object>();
    UserTransaction trx = serviceRegistry.getTransactionService().getUserTransaction();

    try {
      trx.begin();
      System.out.println(trx.hashCode());
      Element args = Arguments.getArguments(req);
      String username =
          args.getElementsByTagName(FORM_PARAM_USERNAME).item(0).getFirstChild().getNodeValue();

      model.put(FTL_USERNAME, username);
      Impersonate.impersonate(username);

      String ref = DocumentUtils.pujarDocumentBase64(req, args, username).trim();
      NodeRef nodeRef = new NodeRef(ref);

      Map<QName, Serializable> props = serviceRegistry.getNodeService().getProperties(nodeRef);
      ContentReader reader =
          serviceRegistry.getContentService().getReader(nodeRef, ContentModel.PROP_CONTENT);
      byte[] contentDecoded =
          es.mityc.firmaJava.libreria.utilidades.Base64.decode(reader.getContentString());
      ContentWriter writer =
          serviceRegistry.getContentService().getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
      writer.putContent(new ByteArrayInputStream(contentDecoded));

      serviceRegistry.getOwnableService().setOwner(nodeRef, username);

      Context cx = Context.enter();
      Scriptable scope = cx.initStandardObjects();
      ScriptNode document = new ScriptNode(nodeRef, serviceRegistry, scope);

      model.put(FTL_DOCUMENT, document);
      model.put(FTL_SUCCESS, String.valueOf(true));

      // Auditar creación de documento
      String type = document.getTypeShort();
      String site = document.getSiteShortName();
      if (type.equals("udl:documentSimple")) {
        AuditUdl.auditRecord(
            auditComponent,
            username,
            document.getNodeRef().toString(),
            AUDIT_ACTION_CREATE_DOCUMENT_SIMPLE,
            type,
            site);
        QName qNameIdDocSimple =
            QName.createQName(
                "http://www.smile.com/model/udl/1.0", "secuencial_identificador_documentSimple");
        String idDocSimple =
            (String) serviceRegistry.getNodeService().getProperty(nodeRef, qNameIdDocSimple);

        if ("".equals(idDocSimple) || idDocSimple == null) {
          // serviceRegistry.getNodeService().deleteNode(nodeRef);
          throw new Exception("Error obtenint identificador via WebService.");
        }
      }

      trx.commit();

    } catch (Exception e) {
      e.printStackTrace();
      model.put(FTL_ERROR, e.getMessage());
      model.put(FTL_SUCCESS, String.valueOf(false));

      try {
        if (trx.getStatus() == javax.transaction.Status.STATUS_ACTIVE) {
          System.out.println(trx.hashCode());
          trx.rollback();
        }
      } catch (SystemException ex) {
        e.printStackTrace();
      }
    }

    return model;
  }