Example #1
0
  // ON veut ajouter ces diplome à la liste des diplomes sans RN...
  public void ajouterRestriction(NSArray listeDipl) {
    EOEditingContext ec = maSession.defaultEditingContext();
    boolean travail = false;

    Enumeration e = listeDipl.objectEnumerator();
    while (e.hasMoreElements()) {
      EOGenericRecord diplSel = (EOGenericRecord) e.nextElement();
      //    		NSLog.out.appendln("A virer : "+diplSel.valueForKey("diplome"));

      // Pas déjà ?
      Integer fspnKey = (Integer) diplSel.valueForKey("fspnKey");
      if (listeEOipDiplSansRn.objectForKey(fspnKey) == null) {

        IpDiplSansRn eoAAjouter = new IpDiplSansRn();
        eoAAjouter.setFannKey((Number) diplSel.valueForKey("fannKey"));
        eoAAjouter.setFspnKey((Number) fspnKey);
        travail = true;
        ec.insertObject(eoAAjouter);
        listeEOipDiplSansRn.setObjectForKey(eoAAjouter, fspnKey);
      }
    }
    if (travail) {
      ec.saveChanges();
      chargerDiplRN();
    }
  }
Example #2
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");
 }
Example #3
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");
 }
Example #4
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;
  }
Example #5
0
 public WOActionResults save() {
   sys.setDataDict(extraData, base);
   sys.setIndexes(indexes, base);
   try {
     ec.saveChanges();
     session().takeValueForKey("parameters saved", "message");
   } catch (Exception e) {
     session().takeValueForKey(e.getMessage(), "message");
   }
   returnPage.ensureAwakeInContext(context());
   return returnPage;
 }
Example #6
0
  /** Deletes the current component */
  public WOComponent deleteComponent() {
    EOEditingContext ec = session().defaultEditingContext();
    Enumeration<SWPictureLink> e = currentComponent.swPictureLinks().objectEnumerator();
    while (e.hasMoreElements()) {
      ec.deleteObject(e.nextElement());
    }
    selectedPage.removeComponent(currentComponent);
    ec.deleteObject(currentComponent);
    ec.saveChanges();

    return null;
  }
Example #7
0
  private void doCreateDummyData() {
    try {
      log.info("load");

      String wordFile = ERXFileUtilities.stringFromFile(new File("/usr/share/dict/words"));
      words = NSArray.componentsSeparatedByString(wordFile, "\n");
      log.info("loaded words: {}", words.count());

      int MAX = 100;
      int MAX_ASSETS = MAX * 10;

      for (int i = 0; i < MAX; i++) {
        Tag tag = Tag.clazz.createAndInsertObject(ec);
        tag.setName(randomWord());
        tags.addObject(tag);
      }
      log.info("created tags: {}", tags.count());

      for (int i = 0; i < MAX; i++) {
        AssetGroup group = AssetGroup.clazz.createAndInsertObject(ec);
        group.setName(randomWord());
        groups.addObject(group);
      }
      log.info("created groups: {}", groups.count());

      for (int i = 0; i < MAX_ASSETS; i++) {
        Asset asset = Asset.clazz.createAndInsertObject(ec);
        asset.setAssetGroup(randomAssetGroup());
        asset.setCreationDate(randomTime());
        asset.setUserCount((long) randomInt(10000));
        asset.setPrice(randomPrice());

        for (int j = 0; j < 10; j++) {
          asset.addToTags(randomTag());
        }

        asset.setContent(randomText(1000));

        asset.setGenericInfo(randomText(1000));

        assets.addObject(asset);
      }
      log.info("created assets: {}", assets.count());

      ec.saveChanges();
      log.info("fin: {}", words.count());
    } catch (IOException e) {
      throw NSForwardException._runtimeExceptionForThrowable(e);
    }
  }
Example #8
0
 public void setReporter(NSDictionary dict) {
   plist = dict;
   String systemName = (String) dict.valueForKey("extSystem");
   sys = ExtSystem.extSystemNamed(systemName, ec, true);
   systemName = (String) dict.valueForKey("extBase");
   if (systemName != null) base = sys.getBase(systemName, true);
   if (ec.hasChanges()) ec.saveChanges();
   NSArray list = (NSArray) plist.valueForKey("extData");
   if (list != null && list.count() > 0) {
     extraData = sys.getDataDict(base);
     if (extraData == null) {
       extraData = new NSMutableDictionary();
     } else {
       dataStyle = "display:none;";
       for (int i = 0; i < list.count(); i++) {
         NSDictionary param = (NSDictionary) list.objectAtIndex(i);
         if (!Various.boolForObject(param.valueForKey("required"))) continue;
         String att = (String) param.valueForKey("attribute");
         if (extraData.valueForKey(att) == null) {
           dataStyle = null;
           break;
         }
       }
     }
   }
   list = (NSArray) plist.valueForKey("indexes");
   if (list != null && list.count() > 0) {
     indexes = sys.getIndexes(base);
     if (indexes == null) indexes = new NSMutableDictionary();
   }
   showSections =
       Various.boolForObject(plist.valueForKey("section"))
           && Various.boolForObject(session().valueForKeyPath("sections.hasSections"));
   if (showSections) section = (SchoolSection) session().valueForKeyPath("state.section");
   String checkAccess = (String) plist.valueForKey("checkAccess");
   access =
       (NSKeyValueCoding)
           session()
               .valueForKeyPath(
                   (checkAccess == null)
                       ? "readAccess.FLAGS.Export"
                       : "readAccess.FLAGS." + checkAccess);
 }
Example #9
0
  // ON veut enlever ces diplome de la liste des diplomes sans RN...
  public void enleverRestriction(NSArray listeDipl) {
    EOEditingContext ec = maSession.defaultEditingContext();
    boolean travail = false;

    Enumeration e = listeDipl.objectEnumerator();
    while (e.hasMoreElements()) {
      EOGenericRecord diplSel = (EOGenericRecord) e.nextElement();
      //  		NSLog.out.appendln("A ajouter : "+diplSel.valueForKey("diplome"));

      if (listeEOipDiplSansRn != null) {
        IpDiplSansRn eoAVirer =
            (IpDiplSansRn)
                listeEOipDiplSansRn.removeObjectForKey((Integer) diplSel.valueForKey("fspnKey"));
        if (eoAVirer != null) {
          ec.deleteObject(eoAVirer);
          travail = true;
        }
      }
    }
    if (travail) {
      ec.saveChanges();
      chargerDiplRN();
    }
  }
Example #10
0
  public WOActionResults export() {
    sys.setDataDict(extraData, base);
    sys.setIndexes(indexes, base);
    if (ec.hasChanges()) {
      try {
        ec.saveChanges();
      } catch (Exception e) {
        session().takeValueForKey(e.getMessage(), "message");
        returnPage.ensureAwakeInContext(context());
        return returnPage;
      }
    }
    NSMutableDictionary reportDict = new NSMutableDictionary();
    reportDict.takeValueForKey(plist, "reporter");
    reportDict.takeValueForKey(section, "section");
    reportDict.takeValueForKey(ec, "ec");
    reportDict.takeValueForKey(indexes, "indexes");
    reportDict.takeValueForKey("ImportExport", "reportDir");
    reportDict.takeValueForKey(session().valueForKey("today"), "today");

    NSMutableDictionary info =
        new NSMutableDictionary(
            MyUtility.presentEduYear((Integer) session().valueForKey("eduYear")), "eduYear");
    info.takeValueForKey(extraData, "extraData");
    NSArray indList = (NSArray) plist.valueForKey("indexes");
    if (indList != null && indList.count() > 0) {
      for (int i = 0; i < indList.count(); i++) {
        NSDictionary ind = (NSDictionary) indList.objectAtIndex(i);
        if (Various.boolForObject(ind.valueForKey("inOptions"))) {
          String indName = (String) ind.valueForKey("name");
          info.takeValueForKey(indexes.valueForKey(indName), indName);
        }
      }
    }
    reportDict.takeValueForKey(info, "info");
    if (returnPage instanceof ImportExport) returnPage.takeValueForKey(plist, "reporter");
    Progress progress = (Progress) pageWithName("Progress");
    progress.returnPage = returnPage;
    progress.resultPath = (String) plist.valueForKey("resultPath");
    if (progress.resultPath == null) progress.resultPath = "result";
    progress.title = (String) plist.valueForKey("title");
    progress.state = XMLGenerator.backgroundGenerate(reportDict);
    return progress.refresh();
    /*
    byte[] result = null;
    try {
    	result = XMLGenerator.generate(session(), (NSMutableDictionary)reportDict);
    } catch (Exception e) {
    	result = WOLogFormatter.formatTrowable(e).getBytes();
    }
    WOResponse response = application().createResponseInContext(context());
    response.setContent(result);
    String contentType = (String)plist.valueForKey("ContentType");
    if(contentType == null)
    	contentType = "application/octet-stream";
    response.setHeader(contentType,"Content-Type");
    StringBuilder buf = new StringBuilder("attachment; filename=\"");
    buf.append("filename");
    contentType = (String)plist.valueForKey("filext");
    if(contentType != null) {
    	if(contentType.charAt(0) != '.')
    		buf.append('.');
    	buf.append(contentType);
    }
    buf.append('"');
    response.setHeader(buf.toString(),"Content-Disposition");
    return response; */
  }
Example #11
0
  // changer la valeur dans la base de l'occurence concernée de l'entite IP_BILANRN_OK
  // SSI la valeur a été changé par l'utilisateur !!!
  private void setEtatRnAff(boolean semImpair, Integer nouvValSessionAutorn) {

    EOGenericRecord leDiplSemCourant;
    if (semImpair) leDiplSemCourant = leDiplSemCourantImpair;
    else leDiplSemCourant = leDiplSemCourantPair;

    int ancValSessionAutorn = getEtatChoixAutorn(semImpair);
    if (ancValSessionAutorn != nouvValSessionAutorn.intValue()) { // alors on a changé qq chose

      String diplome = ((Session) session()).monApp.recuperer1String(leDiplSemCourant, "diplome");
      String mparLibelle =
          ((Session) session()).monApp.recuperer1String(leDiplSemCourant, "mparLibelle");
      int msemOrdre = ((Session) session()).monApp.recuperer1int(leDiplSemCourant, "msemOrdre");
      NSLog.out.appendln(
          "On change l'état pour "
              + diplome
              + ", "
              + mparLibelle
              + " sem."
              + msemOrdre
              + " : passage à "
              + nouvValSessionAutorn);

      //  		MAJ des relationsChips... pour suivre l’ajout des objets
      //  		catSelected.addObjectToBothSidesOfRelationshipWithKey(itemEdit,"items");

      // est-ce que l'on a déjà un EO pour l'entite IP_BILANRN_OK qui serait associée à ce
      // "leDiplSemCourantImpair" ?
      Integer mrsemKey = (Integer) leDiplSemCourant.valueForKey("mrsemKey");
      Integer fannKey = new Integer(((Session) session()).getAnneeEnCours());
      EOEditingContext ec = ((Session) session()).defaultEditingContext();

      Integer etatAutoRN = (Integer) leDiplSemCourant.valueForKey("rnaffEtat");
      if (etatAutoRN == null) { // non : créer le nouvel EO et l'insérer...
        IpBilanrnOk etatAutorn = new IpBilanrnOk();
        etatAutorn.setFannKey(fannKey);
        etatAutorn.setMrsemKey(mrsemKey);
        etatAutorn.setRnaffEtat(nouvValSessionAutorn);
        ec.insertObject(etatAutorn);

      } else {
        // oui : modifier le EO... en commençant par le fetcher...
        NSArray bindings = new NSArray(new Object[] {fannKey, mrsemKey});
        EOQualifier qualifier =
            EOQualifier.qualifierWithQualifierFormat("fannKey = %@ and mrsemKey = %@", bindings);

        EOFetchSpecification fetchSpec = new EOFetchSpecification("IpBilanrnOk", qualifier, null);
        fetchSpec.setRefreshesRefetchedObjects(true);

        NSArray res = ec.objectsWithFetchSpecification(fetchSpec);
        if (res != null && res.count() > 0) {
          IpBilanrnOk etatAutorn = (IpBilanrnOk) res.objectAtIndex(0);
          etatAutorn.setRnaffEtat(nouvValSessionAutorn);
        }
      }

      // sauver le tout...
      ec.saveChanges();

      // TODO : marche pas ci-dessous... faire un reload !
      // leDiplSemCourant.takeStoredValueForKey(new Integer(sessionAutorn), "rnaffEtat");
      monAutornDiplCtrlr.reloaderVueAutoRN(mrsemKey);
    }
  }
  /** Save changes to database */
  public WOComponent saveChanges() {

    Session session = (Session) session();
    EOEditingContext context = session.defaultEditingContext();
    String msg = null;
    ErrorPage errorPage = (ErrorPage) pageWithName("ErrorPage");

    // Verify student's first name
    msg = session.isValidName(student.firstName());
    if (msg != null) {
      errorPage.setErrorMsg(msg);
      errorPage.setNextPage(this);
      return (errorPage);
    }

    // Verify student's last name
    msg = session.isValidName(student.lastName());
    if (msg != null) {
      errorPage.setErrorMsg(msg);
      errorPage.setNextPage(this);
      return (errorPage);
    }

    // Verify student's date of birth
    if (student.dateOfBirth() != null || error != null) {
      error = null;
      msg = session.isValidDate(student.dateOfBirth());
      if (msg != null) {
        errorPage.setErrorMsg(msg);
        errorPage.setNextPage(this);
        return (errorPage);
      }
    }

    // Verify student's street
    if (homeAddress.street() != null) {
      msg = session.isValidStreet(homeAddress.street());
      if (msg != null) {
        errorPage.setErrorMsg(msg);
        errorPage.setNextPage(this);
        return (errorPage);
      }
    }

    // Verify student's city
    if (homeAddress.city() != null) {
      if (homeAddress.city() != null) {
        msg = session.isValidCity(homeAddress.city());
        if (msg != null) {
          errorPage.setErrorMsg(msg);
          errorPage.setNextPage(this);
          return (errorPage);
        }
      }
    }

    // Verify student's state
    if (homeAddress.state() != null) {
      msg = session.isValidState(homeAddress.state());
      if (msg != null) {
        errorPage.setErrorMsg(msg);
        errorPage.setNextPage(this);
        return (errorPage);
      }
    }

    // Verify student's ZIP code
    if (homeAddress.zip() != null) {
      msg = session.isValidZip(homeAddress.zip());
      if (msg != null) {
        errorPage.setErrorMsg(msg);
        errorPage.setNextPage(this);
        return (errorPage);
      }
    }

    // Verify student's email address
    if (homeAddress.emailAddress() != null) {
      msg = session.isValidEmail(homeAddress.emailAddress());
      if (msg != null) {
        errorPage.setErrorMsg(msg);
        errorPage.setNextPage(this);
        return (errorPage);
      }
    }

    // Verify student's login
    msg = session.isValidLogin(student.login());
    if (msg != null) {
      errorPage.setErrorMsg(msg);
      errorPage.setNextPage(this);
      return (errorPage);
    }
    // Verify student's password
    msg = session.isValidPassword(student.password());
    if (msg != null) {
      errorPage.setErrorMsg(msg);
      errorPage.setNextPage(this);
      return (errorPage);
    }

    // Save changes in database
    if (student.firstName() != null && student.lastName() != null) {
      // save changes permanently in database
      context.saveChanges();
    }

    // Add new Student to editing context
    student = new Student();
    homeAddress = new HomeAddress();
    student.setAddress(homeAddress);
    session.defaultEditingContext().insertObject(student);
    session.defaultEditingContext().insertObject(homeAddress);
    return null;
  }
Example #13
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());
    }
  }