public void releaseRecord() throws RecordUnlockedException { checkIsActiveRecordLocked(); SessionState sessionState = getSessionState(); CollectRecord activeRecord = sessionState.getActiveRecord(); if (activeRecord != null && activeRecord.getId() != null) { recordManager.releaseLock(activeRecord.getId()); } sessionState.setActiveRecord(null); }
private CollectRecord createTestRecord( CollectSurvey survey, int internalId, String id, String gpsModel) { CollectRecord record = new CollectRecord(survey, "2.0"); record.setId(internalId); Entity cluster = record.createRootEntity("cluster"); record.setCreationDate(new GregorianCalendar(2011, 11, 31, 23, 59).getTime()); record.setStep(Step.ENTRY); EntityBuilder.addValue(cluster, "id", new Code(id)); EntityBuilder.addValue(cluster, "gps_model", gpsModel); return record; }
private int calculateTotal(List<CollectRecord> recordSummaries) { int count = 0; for (CollectRecord summary : recordSummaries) { int recordStepNumber = summary.getStep().getStepNumber(); for (int stepNumber : stepNumbers) { if (stepNumber <= recordStepNumber) { count++; } } } return count; }
public void checkIsActiveRecordLocked() throws RecordUnlockedException { SessionState sessionState = getSessionState(); CollectRecord record = sessionState.getActiveRecord(); if (record == null) { throw new RecordUnlockedException(); } else if (record.getId() != null) { User user = sessionState.getUser(); String lockId = sessionState.getSessionId(); try { recordManager.checkIsLocked(record.getId(), user, lockId); sessionState.keepActiveRecordAlive(); } catch (RecordUnlockedException e) { clearActiveRecord(); throw e; } } }
private void backup(ZipOutputStream zipOutputStream, List<CollectRecord> recordSummaries) { int total = calculateTotal(recordSummaries); state.setTotal(total); includeIdml(zipOutputStream); for (CollectRecord summary : recordSummaries) { if (!state.isCancelled()) { int recordStepNumber = summary.getStep().getStepNumber(); for (int stepNum : stepNumbers) { if (stepNum <= recordStepNumber) { backup(zipOutputStream, summary, stepNum); state.incrementCount(); } } } else { state.setRunning(false); break; } } }
public void write(CollectRecord record, Writer out) throws IOException, XmlPullParserException { XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); XmlSerializer serializer = factory.newSerializer(); serializer.setFeature(INDENT_FEATURE, true); serializer.setOutput(out); // do not use UTF-8 encoding: unicode text will be escaped by the serializer instead // serializer.startDocument("UTF-8", true); serializer.startDocument(null, true); Entity rootEntity = record.getRootEntity(); String rootEntityName = rootEntity.getName(); serializer.startTag(null, rootEntityName); ModelVersion version = record.getVersion(); if (version != null) { serializer.attribute(null, RECORD_VERSION_ATTRIBUTE, version.getName()); } serializer.attribute( null, RECORD_STEP_ATTRIBUTE, Integer.toString(record.getStep().getStepNumber())); if (record.getState() != null) { serializer.attribute(null, STATE_ATTRIBUTE, record.getState().getCode()); } User createdBy = record.getCreatedBy(); if (createdBy != null) { serializer.attribute(null, RECORD_CREATED_BY_ATTRIBUTE, createdBy.getName()); } User modifiedBy = record.getModifiedBy(); if (modifiedBy != null) { serializer.attribute(null, RECORD_MODIFIED_BY_ATTRIBUTE, modifiedBy.getName()); } addDateAttribute(serializer, RECORD_CREATED_ATTRIBUTE, record.getCreationDate()); addDateAttribute(serializer, RECORD_MODIFIED_ATTRIBUTE, record.getModifiedDate()); writeChildren(serializer, rootEntity); serializer.endTag(null, rootEntityName); serializer.endDocument(); serializer.flush(); }
private void backup(ZipOutputStream zipOutputStream, CollectRecord summary, int stepNumber) { Integer id = summary.getId(); try { CollectRecord record = recordManager.load(survey, id, stepNumber); String entryFileName = buildEntryFileName(record, stepNumber); ZipEntry entry = new ZipEntry(entryFileName); zipOutputStream.putNextEntry(entry); OutputStreamWriter writer = new OutputStreamWriter(zipOutputStream); dataMarshaller.write(record, writer); zipOutputStream.closeEntry(); zipOutputStream.flush(); } catch (Exception e) { String message = "Error while backing up " + id + " " + e.getMessage(); if (LOG.isErrorEnabled()) { LOG.error(message, e); } throw new RuntimeException(message, e); } }
private String buildEntryFileName(CollectRecord record, int stepNumber) { return stepNumber + File.separator + record.getId() + ".xml"; }