public Constraint resolve(Form form) throws SAXException, IllegalArgumentException, NullPointerException, ParseException { // Form checks: if (form == null) throw new NullPointerException("Non-null form is needed to resolve Constraint"); if (!form.isProducesRecords()) { addWarning( "Cannot impose constraint on records of form \"" + form.id + "\" because it does not produce data records."); return null; } // Get column: @SuppressWarnings("unchecked") ColumnPointer<ComparableColumn<?>> columnPointer = (ColumnPointer<ComparableColumn<?>>) ColumnPointer.ByName( form.getSchema(), columnName, true, true); // will throw IllegalArgumentException if no such column is found (but name // sanitation will be used first) // Column check: if (!(columnPointer.getColumn() instanceof ComparableColumn<?>)) throw new SAXException( "Constraint refers to a column (\"" + columnName + "\") which is not comparable."); // Return RuleConstraint: return RuleConstraint.FromString(columnPointer, comparison, valueString); }
/* (non-Javadoc) * @see uk.ac.ucl.excites.sapelli.collector.db.ProjectStore#doAdd(uk.ac.ucl.excites.sapelli.collector.model.Project) */ @Override protected void doAdd(Project project) throws ProjectIdentificationClashException, ProjectSignatureClashException, IllegalStateException { try { // Note: we use insert() instead of store() to not allow updates // Store project record: rsWrapper.recordStore.insert(getProjectRecord(project)); // Store an FSI record for each record-producing form: for (Form form : project.getForms()) if (form.isProducesRecords()) rsWrapper.recordStore.insert(getFSIRecord(form)); // Cache the project: cacheProject(project); } catch (DBPrimaryKeyException dbPKE) { throw new ProjectIdentificationClashException(project, false); } catch (DBConstraintException dbCE) { throw new ProjectSignatureClashException(project); } catch (DBException e) { e.printStackTrace(System.err); throw new IllegalStateException(e); } }
@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); } } } }
private RecordReference getFSIRecordReference(Form form) { return FSI_SCHEMA.createRecordReference( getProjectRecordReference(form.project), form.getPosition()); }
private Record getFSIRecord(Form form) { return FSI_SCHEMA.createRecord( getProjectRecordReference(form.project), form.getPosition(), form.getColumnOptionalityAdvisor().getIDsOfByPassableNonOptionalFieldsWithColumn()); }