コード例 #1
0
 @Override
 public RecordReference retrieveHeldForeignKey(Relationship relationship) {
   if (!relationship.isHoldForeignRecord())
     throw new IllegalArgumentException(
         "This relationship is not allowed to hold on to foreign records");
   String prefKey = getHeldForeignKeyPrefKey(relationship);
   String serialisedForeignKey = preferences.getString(prefKey, null);
   if (serialisedForeignKey != null)
     try {
       return relationship
           .getRelatedForm()
           .getSchema()
           .createRecordReference(serialisedForeignKey);
     } catch (Exception e) {
       deleteHeldForeignKey(relationship);
     }
   return null;
 }
コード例 #2
0
 @Override
 public void storeHeldForeignKey(Relationship relationship, RecordReference foreignKey) {
   if (!relationship.isHoldForeignRecord())
     throw new IllegalArgumentException(
         "This relationship is not allowed to hold on to foreign records");
   preferences
       .edit()
       .putString(getHeldForeignKeyPrefKey(relationship), foreignKey.serialise())
       .commit();
 }
コード例 #3
0
 /* (non-Javadoc)
  * @see uk.ac.ucl.excites.sapelli.collector.db.ProjectStore#retrieveHeldForeignKey(uk.ac.ucl.excites.sapelli.collector.model.fields.Relationship)
  */
 @Override
 public RecordReference retrieveHeldForeignKey(Relationship relationship) {
   Record hfkRecord = null;
   try {
     hfkRecord = rsWrapper.recordStore.retrieveRecord(getHFKRecordReference(relationship));
     return relationship
         .getRelatedForm()
         .getSchema()
         .createRecordReference(HFK_SERIALISED_RECORD_REFERENCE.retrieveValue(hfkRecord));
   } catch (Exception e) {
     if (hfkRecord != null) deleteHeldForeignKey(relationship);
   }
   // else:
   return null;
 }
コード例 #4
0
ファイル: ProjectParser.java プロジェクト: periclesjr/Sapelli
  @Override
  protected void parseEndElement(String uri, String localName, String qName) throws Exception {
    // </Sapelli-Collector-Project>, or </ExCiteS-Collector-Project> (for backwards compatibility)
    if (qName.equals(TAG_PROJECT) || qName.equals(TAG_PROJECT_V1X)) {
      clearSubtreeParsers();

      if (project.getForms().size() == 0)
        throw new SAXException("A project such have at least 1 form!");
      else {
        // Resolve startForm
        Form startForm =
            project.getForm(
                startFormID); // will return null if startFormID is null or there is no form with
        // that name, uses equalsIgnoreCase()
        if (startForm != null) project.setStartForm(startForm);
        // else: first form of project will remain the startForm

        // Resolve form relationships:
        if (relationshipToFormID != null)
          for (Entry<Relationship, String> entry : relationshipToFormID.entrySet()) {
            Relationship rel = entry.getKey();
            Form relatedForm = project.getForm(entry.getValue()); // uses equalsIgnoreCase()
            if (relatedForm == null)
              throw new SAXException(
                  "Relationship \""
                      + rel.id
                      + "\" in form \""
                      + rel.form.id
                      + "\" refers to unknown related form \""
                      + entry.getValue()
                      + "\".");
            rel.setRelatedForm(
                relatedForm); // will trigger initialisation of Schema of relatedForm (this should
            // not be a problem, it will not be done again below)
          }

        // Initialise forms...
        for (Form form : project.getForms()) {
          try {
            // generates Schema, Columns & ValueDictionaries:
            form.initialiseStorage(
                fsiProvider != null
                    ? fsiProvider.getByPassableFieldIDs(form)
                    : null); // Note: fsiProvider will be null if this project is loaded/parsed for
            // the first time
          } catch (ModelFullException mfe) {
            throw new SAXException(
                "This project contains more data-producing Forms than allowed (maximum: "
                    + Project.MAX_RECORD_PRODUCING_FORMS
                    + ").");
          } catch (DuplicateColumnException dce) {
            throw new SAXException(
                "Duplicate column name (\""
                    + dce.getColumnName()
                    + "\") in schema for form \""
                    + form.id
                    + "\".");
          }
          addWarnings(form.getWarnings()); // !!!
          form.clearWarnings();
        }
        // Seal project model:
        project.getModel().seal();

        // Resolve relationship constraints:
        if (relationshipToConstraints != null)
          for (Entry<Relationship, List<ConstraintDescription>> entry :
              relationshipToConstraints.entrySet())
            for (ConstraintDescription constrDesc : entry.getValue())
              try {
                Relationship rel = entry.getKey();
                rel.addConstraint(constrDesc.resolve(rel.getRelatedForm()));
              } catch (Exception e) {
                throw new Exception(
                    "Error upon resolving constraint on Relationship \"" + entry.getKey().id + "\"",
                    e);
              }
      }
    }
  }