use of org.openforis.idm.model.Entity in project collect by openforis.
the class CSVDataImportProcess method setValuesInRecord.
private boolean setValuesInRecord(DataLine line, CollectRecord record, Step step) {
// LOG.info("Setting values in record: " + record.getId() + "[" + record.getRootEntityKeyValues() + "]" + " step: " + step);
record.setStep(step);
Entity parentEntity = getOrCreateParentEntity(record, line);
if (parentEntity == null) {
// TODO add parsing error?
return false;
} else {
setValuesInAttributes(parentEntity, line);
return true;
}
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class DataRestoreSummaryTask method findAlreadyExistingFullRecordSummary.
private CollectRecordSummary findAlreadyExistingFullRecordSummary(int entryId, Step step, CollectRecord parsedRecord) {
List<String> keyValues = parsedRecord.getRootEntityKeyValues();
Entity rootEntity = parsedRecord.getRootEntity();
int rootEntityDefId = rootEntity.getDefinition().getId();
RecordFilter filter = new RecordFilter(survey);
filter.setRootEntityId(rootEntityDefId);
filter.setKeyValues(keyValues);
List<CollectRecordSummary> oldRecordSummaries = recordManager.loadSummaries(filter);
if (oldRecordSummaries == null || oldRecordSummaries.isEmpty()) {
return null;
} else if (oldRecordSummaries.size() == 1) {
CollectRecordSummary summary = oldRecordSummaries.get(0);
CollectRecord record = recordManager.load(survey, summary.getId(), summary.getStep(), fullSummary);
CollectRecordSummary recordSummary = CollectRecordSummary.fromRecord(record);
recordSummary.setFiles(recordFileManager.getAllFiles(record));
return recordSummary;
} else {
String errorMessage = String.format("Data file: %s - multiple records found in survey %s with key(s) %s", getEntryName(entryId, step), survey.getName(), keyValues);
throw new IllegalStateException(errorMessage);
}
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class AddNodeCommandHandler method execute.
@Override
public List<RecordEvent> execute(C command) {
CollectRecord record = findRecord(command);
Entity parentEntity = record.findNodeByPath(command.getParentEntityPath());
NodeDefinition nodeDef = parentEntity.getDefinition().getChildDefinition(command.getNodeDefId());
NodeChangeSet changeSet = recordUpdater.addNode(parentEntity, nodeDef);
recordManager.save(record);
List<RecordEvent> events = new EventProducer().produceFor(changeSet, command.getUsername());
return events;
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class EventProducer method produceFor.
public List<RecordEvent> produceFor(CollectRecord record, final String userName) {
final List<RecordEvent> events = new ArrayList<RecordEvent>();
final Integer recordId = record.getId();
final RecordStep recordStep = record.getStep().toRecordStep();
record.getRootEntity().traverse(new NodeVisitor() {
public void visit(Node<? extends NodeDefinition> node, int idx) {
NodeDefinition nodeDef = node.getDefinition();
List<String> ancestorIds = getAncestorIds(nodeDef, node.getAncestorIds());
EventFactory factory = new EventFactory(recordId, recordStep, ancestorIds, node, userName);
if (node instanceof Entity) {
events.addAll(factory.entityCreated());
} else if (node instanceof Attribute) {
if (nodeDef.isMultiple()) {
events.addAll(factory.attributeCreated());
} else {
events.addAll(factory.attributeUpdated());
}
}
}
});
return events;
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class RecordDaoTest method createRecord.
private CollectRecord createRecord(CollectSurvey survey, int sequenceNumber) {
int skippedCount = new Double(Math.ceil((double) (Math.random() * 40))).intValue();
int missingCount = new Double(Math.ceil((double) (Math.random() * 50))).intValue();
int errorsCount = new Double(Math.ceil((double) (Math.random() * 10))).intValue();
int warningsCount = new Double(Math.ceil((double) (Math.random() * 30))).intValue();
int numberOfPlots = new Double(Math.ceil((double) (Math.random() * 20))).intValue();
int numberOfTrees = new Double(Math.ceil((double) (Math.random() * 30))).intValue();
;
CollectRecord record = new CollectRecord(recordManager, survey, "2.0");
record.setCreationDate(new GregorianCalendar(2011, 0, sequenceNumber, 8, 30).getTime());
// record.setCreatedBy("ModelDaoIntegrationTest");
record.setStep(Step.ENTRY);
record.setModifiedDate(new GregorianCalendar(2011, 1, sequenceNumber, 8, 30).getTime());
record.setSkipped(skippedCount);
record.setMissing(missingCount);
record.setErrors(errorsCount);
record.setWarnings(warningsCount);
Entity cluster = record.createRootEntity("cluster");
String keyId = Integer.toString(sequenceNumber);
EntityBuilder.addValue(cluster, "id", new Code(keyId));
EntityBuilder.addValue(cluster, "gps_realtime", Boolean.TRUE);
EntityBuilder.addValue(cluster, "region", new Code("001"));
EntityBuilder.addValue(cluster, "district", new Code("002"));
EntityBuilder.addValue(cluster, "vehicle_location", new Coordinate(432423423l, 4324324l, "srs"));
EntityBuilder.addValue(cluster, "gps_model", "TomTom 1.232");
{
Entity ts = EntityBuilder.addEntity(cluster, "time_study");
ts.addValue("date", new Date(2011, 2, 14));
ts.addValue("start_time", new Time(8, 15));
ts.addValue("end_time", new Time(15, 29));
}
{
Entity ts = EntityBuilder.addEntity(cluster, "time_study");
ts.addValue("date", new Date(2011, 2, 15));
ts.addValue("start_time", new Time(8, 32));
ts.addValue("end_time", new Time(11, 20));
}
for (int i = 0; i < numberOfPlots; i++) {
Entity plot = EntityBuilder.addEntity(cluster, "plot");
EntityBuilder.addValue(plot, "no", new Code(Integer.toString(i + 1)));
for (int j = 0; j < numberOfTrees; j++) {
Entity tree = EntityBuilder.addEntity(plot, "tree");
tree.addValue("dbh", 54.2);
tree.addValue("total_height", 2.0);
RealAttribute boleHeight = tree.addValue("bole_height", (Double) null);
boleHeight.getField().setSymbol('*');
boleHeight.getField().setRemarks("No value specified");
// .setMetadata(new CollectAttributeMetadata('*',null,"No value specified"));
}
}
// set counts
record.getEntityCounts().add(numberOfPlots);
// set keys
record.getRootEntityKeys().add(keyId);
return record;
}
Aggregations