Beispiel #1
0
 public WOActionResults delete() {
   EOEditingContext ec = (EOEditingContext) valueForBinding("ec");
   ec.lock();
   try {
     NSArray usage =
         EOUtilities.objectsMatchingKeyAndValue(ec, "ItogTypeList", "itogType", currType);
     if (usage != null && usage.count() > 0) {
       Enumeration enu = usage.objectEnumerator();
       while (enu.hasMoreElements()) {
         EOEnterpriseObject itl = (EOEnterpriseObject) enu.nextElement();
         ec.deleteObject(itl);
       }
     }
     ec.deleteObject(currType);
     ec.saveChanges();
     currType = null;
     setValueForBinding(currType, "currType");
   } catch (Exception e) {
     SetupItogs.logger.log(WOLogLevel.WARNING, "Error saving changes in list ", e);
     session().takeValueForKey(e.getMessage(), "message");
     ec.revert();
   } finally {
     ec.unlock();
   }
   return (WOActionResults) valueForBinding("actionResult");
 }
  public ERJRFetchSpecificationReportTask(
      EOFetchSpecification fetchSpecification,
      String jasperCompiledReportFileName,
      String frameworkName,
      HashMap<String, Object> parameters) {
    ERXAssert.PRE.notNull(fetchSpecification);
    ERXAssert.PRE.notNull(jasperCompiledReportFileName);

    // Since it is likely the fetch spec will be used in a different
    // background thread during report generation, we need to ensure we have a schema-based
    // qualifier instead of a memory-based qualifier that might have references to EOs
    // in an RR-locked editing context
    EOFetchSpecification fs = null;
    EOEditingContext ec = ERXEC.newEditingContext();
    ec.lock();
    try {
      fs = schemaBasedFetchSpecification(fetchSpecification);
    } catch (Exception e) {
      throw new RuntimeException("Failed to convert fetchSpecification to schema-based", e);
    } finally {
      ec.unlock();
    }
    this.fetchSpecification = fs;

    this.jasperCompiledReportFileName = jasperCompiledReportFileName;
    this.frameworkName = frameworkName;
    this.parameters = parameters;

    if (this.parameters == null) {
      this.parameters = new HashMap<String, Object>();
    }
  }
Beispiel #3
0
 public WOActionResults saveType() {
   EOEditingContext ec = (EOEditingContext) valueForBinding("ec");
   ec.lock();
   try {
     boolean newType = (currType == null);
     if (newType) {
       currType = (ItogType) EOUtilities.createAndInsertInstance(ec, ItogType.ENTITY_NAME);
       Number maxSort = (Number) valueForBinding("maxSort");
       if (maxSort != null) {
         currType.setSort(new Integer(maxSort.intValue() + 1));
       } else {
         currType.setSort(new Integer(1));
       }
     }
     currType.setName(itogName);
     currType.setTitle(itogTitle);
     currType.setInYearCount((itogCount == null) ? new Integer(0) : itogCount);
     ec.saveChanges();
     //			if(newType) {
     //				allTypes = allTypes.arrayByAddingObject(currType);
     //				itogsList = NSArray.EmptyArray;
     //			}
     setValueForBinding(currType, "currType");
   } catch (Exception e) {
     SetupItogs.logger.log(WOLogLevel.WARNING, "Error saving changes in list ", e);
     session().takeValueForKey(e.getMessage(), "message");
     ec.revert();
   } finally {
     ec.unlock();
   }
   return (WOActionResults) valueForBinding("actionResult");
 }
  private File _call() {
    // If development
    if (ERXApplication.isDevelopmentModeSafe()) {
      parameters.put("_isDevelopmentMode", Boolean.TRUE);
    } else {
      parameters.put("_isDevelopmentMode", Boolean.FALSE);
    }

    reportFile = null;

    if (log.isDebugEnabled()) log.debug("Starting JasperReportTask: " + toString());
    EOEditingContext ec = ERXEC.newEditingContext();
    ec.lock();
    try {

      @SuppressWarnings("unchecked")
      NSArray<EOEnterpriseObject> objects = ec.objectsWithFetchSpecification(fetchSpecification);

      jrDataSource = new ERJRFoundationDataSource(objects);

      if (jasperCompiledReportFileName != null) {
        reportFile =
            ERJRUtilities.runCompiledReportToPDFFile(
                jasperCompiledReportFileName, frameworkName, parameters, jrDataSource);
      }

    } catch (Exception e) {
      throw new NestableRuntimeException(e);
    } finally {
      ec.unlock();
    }

    return reportFile;
  }
Beispiel #5
0
  public WOActionResults createDataStore() throws IOException, MessagingException {
    File emailFile = new File("Resources/largeEmail.eml");
    javax.mail.Message message = convertEmlToMessage(emailFile);

    EOObjectStore osc = new ERXObjectStoreCoordinator(true);
    EOEditingContext ec = ERXEC.newEditingContext(osc);
    ec.lock();
    try {
      DataContainer container =
          (DataContainer)
              EOUtilities.createAndInsertInstance(ec, DataContainer.class.getSimpleName());

      DataStore dataStore =
          (DataStore) EOUtilities.createAndInsertInstance(ec, DataStore.class.getSimpleName());
      dataStore.setDataContainer(container);

      ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
      message.writeTo(byteStream);
      NSData rawEmail = new NSData(byteStream.toByteArray());
      dataStore.setData(rawEmail);

      ec.saveChanges();
    } finally {
      ec.unlock();
      ec.dispose();
      osc.dispose();
      ec = null;
      osc = null;
    }
    return null;
  }
Beispiel #6
0
 public void createDummyData() {
   ec = ERXEC.newEditingContext();
   ec.lock();
   try {
     doCreateDummyData();
   } finally {
     ec.unlock();
   }
 }
Beispiel #7
0
 public void createTables() {
   ec = ERXEC.newEditingContext();
   ec.lock();
   try {
     boolean dropTables = ERXProperties.booleanForKeyWithDefault("dropTables", true);
     createTables(dropTables);
   } finally {
     ec.unlock();
   }
 }
Beispiel #8
0
  public Main(WOContext context) {
    super(context);

    // The memory leak doesn't happen unless there are multiple OSCs registered with
    // ERXObjectStoreCoordinatorSynchronizer._coordinators. Using an OSC (performing a lookup, etc,
    // as below) causes the OSC to be added to the _coordinators array.
    EOEditingContext ec = ERXEC.newEditingContext(_osc);
    ec.lock();
    try {
      NSArray dcArray = EOUtilities.objectsForEntityNamed(ec, "DataContainer");
    } finally {
      ec.unlock();
      ec.dispose();
      ec = null;
    }
  }
Beispiel #9
0
 @Override
 protected void handleUnsuccessfullQueryForKey(Object key) {
   EOEditingContext ec = ERXEC.newEditingContext();
   EOGlobalID gid = NO_GID_MARKER;
   ec.lock();
   try {
     EOEnterpriseObject eo =
         (EOEnterpriseObject)
             EOUtilities.objectsMatchingKeyAndValue(ec, ENTITY, Key.KEY, key).lastObject();
     if (eo != null) {
       gid = ec.globalIDForObject(eo);
     }
   } finally {
     ec.unlock();
   }
   cache().setObjectForKey(createRecord(gid, null), key);
 }
  /**
   * Ensures we don't have references to EOs before using this in the background thread.
   *
   * @param fs
   * @return a clone of the fetchSpecification with the EOQualifier converted to a schema-based
   *     qualifier or the same {@link EOFetchSpecification} if there is no qualifier.
   */
  private EOFetchSpecification schemaBasedFetchSpecification(
      EOFetchSpecification fetchSpecification) {

    EOQualifier q = fetchSpecification.qualifier();
    if (q != null) {

      // Clone the fetchSpec
      fetchSpecification = (EOFetchSpecification) fetchSpecification.clone();

      EOEditingContext ec = ERXEC.newEditingContext();
      ec.lock();
      try {
        EOEntity entity =
            ERXEOAccessUtilities.entityMatchingString(ec, fetchSpecification.entityName());
        // Convert the qualifier to a schema-based qualifier
        q = entity.schemaBasedQualifier(q);
        fetchSpecification.setQualifier(q);
      } finally {
        ec.unlock();
      }
    } // ~ if (q != null)
    return fetchSpecification;
  }
  @Override
  public WOResponse handleRequest(WORequest request) {
    int bufferSize = 16384;

    WOApplication application = WOApplication.application();
    application.awake();
    try {
      WOContext context = application.createContextForRequest(request);
      WOResponse response = application.createResponseInContext(context);

      String sessionIdKey = application.sessionIdKey();
      String sessionId = (String) request.formValueForKey(sessionIdKey);
      if (sessionId == null) {
        sessionId = request.cookieValueForKey(sessionIdKey);
      }
      context._setRequestSessionID(sessionId);
      if (context._requestSessionID() != null) {
        application.restoreSessionWithID(sessionId, context);
      }

      try {
        final WODynamicURL url = request._uriDecomposed();
        final String requestPath = url.requestHandlerPath();
        final Matcher idMatcher = Pattern.compile("^id/(\\d+)/").matcher(requestPath);

        final Integer requestedAttachmentID;
        String requestedWebPath;

        final boolean requestedPathContainsAnAttachmentID = idMatcher.find();
        if (requestedPathContainsAnAttachmentID) {
          requestedAttachmentID = Integer.valueOf(idMatcher.group(1));
          requestedWebPath = idMatcher.replaceFirst("/");
        } else {
          // MS: This is kind of goofy because we lookup by path, your web path needs to
          // have a leading slash on it.
          requestedWebPath = "/" + requestPath;
          requestedAttachmentID = null;
        }

        try {
          InputStream attachmentInputStream;
          String mimeType;
          String fileName;
          long length;
          String queryString = url.queryString();
          boolean proxyAsAttachment =
              (queryString != null && queryString.contains("attachment=true"));

          EOEditingContext editingContext = ERXEC.newEditingContext();
          editingContext.lock();

          try {
            ERAttachment attachment =
                fetchAttachmentFor(editingContext, requestedAttachmentID, requestedWebPath);

            if (_delegate != null && !_delegate.attachmentVisible(attachment, request, context)) {
              throw new SecurityException("You are not allowed to view the requested attachment.");
            }
            mimeType = attachment.mimeType();
            length = attachment.size().longValue();
            fileName = attachment.originalFileName();
            ERAttachmentProcessor<ERAttachment> attachmentProcessor =
                ERAttachmentProcessor.processorForType(attachment);
            if (!proxyAsAttachment) {
              proxyAsAttachment = attachmentProcessor.proxyAsAttachment(attachment);
            }
            InputStream rawAttachmentInputStream =
                attachmentProcessor.attachmentInputStream(attachment);
            attachmentInputStream = new BufferedInputStream(rawAttachmentInputStream, bufferSize);
          } finally {
            editingContext.unlock();
          }

          response.setHeader(mimeType, "Content-Type");
          response.setHeader(String.valueOf(length), "Content-Length");

          if (proxyAsAttachment) {
            response.setHeader("attachment; filename=\"" + fileName + "\"", "Content-Disposition");
          }

          response.setStatus(200);
          response.setContentStream(attachmentInputStream, bufferSize, length);
        } catch (SecurityException e) {
          NSLog.out.appendln(e);
          response.setContent(e.getMessage());
          response.setStatus(403);
        } catch (NoSuchElementException e) {
          NSLog.out.appendln(e);
          response.setContent(e.getMessage());
          response.setStatus(404);
        } catch (FileNotFoundException e) {
          NSLog.out.appendln(e);
          response.setContent(e.getMessage());
          response.setStatus(404);
        } catch (IOException e) {
          NSLog.out.appendln(e);
          response.setContent(e.getMessage());
          response.setStatus(500);
        }

        return response;
      } finally {
        if (context._requestSessionID() != null) {
          WOApplication.application().saveSessionForContext(context);
        }
      }
    } finally {
      application.sleep();
    }
  }
Beispiel #12
0
  // ----------------------------------------------------------
  public void takeFormValues(NSDictionary<?, ?> formValues) {
    WCConfigurationFile configuration = Application.configurationProperties();
    if (log.isDebugEnabled()) {
      log.debug("takeFormValues(): initial config = ");
      log.debug(configuration.configSettingsAsString());
    }
    String email =
        storeFormValueToConfig(
            formValues, "coreAdminEmail", "Please specify the administrator's e-mail address.");
    storeFormValueToConfig(formValues, "adminNotifyAddrs", null);
    String authDomainName = configuration.getProperty("authenticator.default");
    String username =
        storeFormValueToConfig(
            formValues, "AdminUsername", "Please specify the administrator's user name.");
    if (log.isDebugEnabled()) {
      log.debug("takeFormValues(): middle = ");
      log.debug(configuration.configSettingsAsString());
    }
    if (authDomainName == null || authDomainName.equals("")) {
      error("Cannot identify default institution's " + "authentication configuration.");
    } else if (username != null && !hasMessages()) {
      EOEditingContext ec = WCEC.newEditingContext();
      try {
        ec.lock();
        AuthenticationDomain domain = AuthenticationDomain.authDomainByName(authDomainName);
        NSArray<?> users =
            EOUtilities.objectsMatchingValues(
                ec,
                User.ENTITY_NAME,
                new NSDictionary<String, Object>(
                    new Object[] {username, domain},
                    new String[] {User.USER_NAME_KEY, User.AUTHENTICATION_DOMAIN_KEY}));
        User admin;
        if (users.count() > 0) {
          admin = (User) users.objectAtIndex(0);
          admin.setEmail(email);
          String first = extractFormValue(formValues, "AdminFirstName");
          if (first != null && !first.equals("")) {
            admin.setFirstName(first);
          }
          String last = extractFormValue(formValues, "AdminLastName");
          if (last != null && !last.equals("")) {
            admin.setLastName(last);
          }
          ec.saveChanges();
        } else {
          String password =
              storeFormValueToConfig(
                  formValues, "AdminPassword", "An administrator password is required.");
          if (authDomainName.equals(DatabaseAuthenticator.class.getName())
              && (password == null || password.equals(""))) {
            // Don't need this anymore, since the error message is
            // posted by storeFormValuesToConfig() above.

            // errorMessage(
            //     "An administrator password is required." );
          } else {
            admin = User.createUser(username, password, domain, (byte) 100, ec);
            admin.setEmail(email);
            String first = extractFormValue(formValues, "AdminFirstName");
            if (first != null && !first.equals("")) {
              admin.setFirstName(first);
            }
            String last = extractFormValue(formValues, "AdminLastName");
            if (last != null && !last.equals("")) {
              admin.setLastName(last);
            }
            ec.saveChanges();
          }
        }
      } finally {
        ec.unlock();
        ec.dispose();
      }
    }
    if (log.isDebugEnabled()) {
      log.debug("takeFormValues(): near end = ");
      log.debug(configuration.configSettingsAsString());
    }
    if (!hasMessages()) {
      configuration.remove("AdminFirstName");
      configuration.remove("AdminLastName");
    }
    if (log.isDebugEnabled()) {
      log.debug("takeFormValues(): finals = ");
      log.debug(configuration.configSettingsAsString());
    }
  }