use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class SurveyManager method updateTemporaryModel.
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public CollectSurvey updateTemporaryModel(File surveyFile, boolean validate, UserGroup userGroup) throws SurveyValidationException, SurveyStoreException {
CollectSurvey parsedSurvey;
try {
parsedSurvey = unmarshalSurvey(surveyFile, validate, false);
} catch (IdmlParseException e) {
throw new SurveyImportException(e);
}
String uri = parsedSurvey.getUri();
SurveySummary oldTemporarySurvey = loadTemporarySummaryByUri(uri);
if (oldTemporarySurvey == null) {
throw new IllegalArgumentException("Survey to update not found: " + uri);
} else {
int oldSurveyId = oldTemporarySurvey.getId();
parsedSurvey.setId(oldSurveyId);
parsedSurvey.setName(oldTemporarySurvey.getName());
parsedSurvey.setPublishedId(oldTemporarySurvey.getPublishedId());
parsedSurvey.setTemporary(true);
parsedSurvey.setUserGroup(userGroup);
// clean code list items
for (CodeList codeList : parsedSurvey.getCodeLists()) {
codeList.removeAllItems();
}
codeListManager.deleteAllItemsBySurvey(oldSurveyId, true);
save(parsedSurvey);
// import code list items
try {
codeListManager.importCodeLists(parsedSurvey, surveyFile);
} catch (CodeListImportException e) {
throw new SurveyImportException(e);
}
}
return parsedSurvey;
}
use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class SurveyValidator method validateCodeLists.
private List<SurveyValidationResult> validateCodeLists(CollectSurvey survey, ValidationParameters validationParameters) {
List<SurveyValidationResult> results = new ArrayList<SurveyValidationResult>();
for (CodeList list : survey.getCodeLists()) {
if (!survey.isPredefinedCodeList(list)) {
if (validationParameters.warnOnUnusedCodeLists && !codeListManager.isInUse(list)) {
// unused code list not allowed
SurveyValidationResult validationResult = new SurveyValidationResult(Flag.WARNING, String.format(CODE_LIST_PATH_FORMAT, list.getName()), "survey.validation.error.unused_code_list");
results.add(validationResult);
} else if (validationParameters.warnOnEmptyCodeLists && !list.isExternal() && codeListManager.isEmpty(list)) {
// empty code list not allowed
SurveyValidationResult validationResult = new SurveyValidationResult(Flag.WARNING, String.format(CODE_LIST_PATH_FORMAT, list.getName()), "survey.validation.error.empty_code_list");
results.add(validationResult);
}
}
}
return results;
}
use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class RecordUpdater method addEmptyEnumeratedEntities.
private void addEmptyEnumeratedEntities(Entity parentEntity, EntityDefinition enumerableEntityDefn) {
Record record = parentEntity.getRecord();
ModelVersion version = record.getVersion();
CodeAttributeDefinition enumeratingCodeDefn = enumerableEntityDefn.getEnumeratingKeyCodeAttribute(version);
if (enumeratingCodeDefn != null) {
CodeList list = enumeratingCodeDefn.getList();
Survey survey = record.getSurvey();
CodeListService codeListService = survey.getContext().getCodeListService();
List<CodeListItem> items = codeListService.loadRootItems(list);
int i = 0;
for (CodeListItem item : items) {
if (version == null || version.isApplicable(item)) {
String code = item.getCode();
Entity enumeratedEntity = parentEntity.getEnumeratedEntity(enumerableEntityDefn, enumeratingCodeDefn, code);
if (enumeratedEntity == null) {
Entity addedEntity = performEntityAdd(parentEntity, enumerableEntityDefn, i);
addEmptyNodes(addedEntity);
// set the value of the key CodeAttribute
CodeAttribute addedCode = (CodeAttribute) addedEntity.getChild(enumeratingCodeDefn, 0);
addedCode.setValue(new Code(code));
addedCode.updateSummaryInfo();
} else if (enumeratedEntity.getIndex() != i) {
parentEntity.move(enumerableEntityDefn, enumeratedEntity.getIndex(), i);
}
i++;
}
}
}
}
use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class UICodeField method getListId.
public Integer getListId() {
CodeAttributeDefinition attrDef = (CodeAttributeDefinition) getAttributeDefinition();
CodeList list = attrDef.getList();
return list == null ? null : list.getId();
}
use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class CodeAttributeProxy method isExternalCodeList.
protected boolean isExternalCodeList() {
CodeAttributeDefinition defn = codeAttribute.getDefinition();
CodeList list = defn.getList();
return list.isExternal();
}
Aggregations