private void buildInputs(String fileName) throws DCInputsReaderException { formDefns = new HashMap<String, List<List<Map<String, String>>>>(); valuePairs = new HashMap<String, List<String>>(); String uri = "file:" + new File(fileName).getAbsolutePath(); try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); factory.setIgnoringComments(true); factory.setIgnoringElementContentWhitespace(true); DocumentBuilder db = factory.newDocumentBuilder(); Document doc = db.parse(uri); doNodes(doc); checkValues(); } catch (FactoryConfigurationError fe) { throw new DCInputsReaderException("Cannot create Submission form parser", fe); } catch (Exception e) { throw new DCInputsReaderException("Error creating submission forms: " + e); } }
@Override public void init(Curator curator, String taskId) throws IOException { super.init(curator, taskId); try { reader = new DCInputsReader(); } catch (DCInputsReaderException dcrE) { throw new IOException(dcrE.getMessage(), dcrE); } }
if (v == null) { String errString = "Cannot find value pairs for " + pairsName; throw new DCInputsReaderException(errString);
@Override public Choices getMatches(String field, String query, Collection collection, int start, int limit, String locale) { String formName; try { init(); if (collection == null) { Set<Choice> choices = new HashSet<Choice>(); //workaround search in all authority configured for (ChoiceAuthority ca : delegates.values()) { Choices tmp = ca.getMatches(field, query, null, start, limit, locale); if (tmp.total > 0) { Set<Choice> mySet = new HashSet<Choice>(Arrays.asList(tmp.values)); choices.addAll(mySet); } } if (!choices.isEmpty()) { Choice[] results = new Choice[choices.size() - 1]; choices.toArray(results); return new Choices(results, 0, choices.size(), Choices.CF_AMBIGUOUS, false); } } else { formName = dci.getInputFormNameByCollectionAndField(collection, field); return delegates.get(formName).getMatches(field, query, collection, start, limit, locale); } } catch (DCInputsReaderException e) { log.error(e.getMessage(), e); } return new Choices(Choices.CF_NOTFOUND); }
throw new DCInputsReaderException("Form " + formName + "row " + rowIdx + " has no fields");
@Override public Choices getBestMatch(String field, String text, Collection collection, String locale) { String formName; try { init(); if (collection == null) { Set<Choice> choices = new HashSet<Choice>(); //workaround search in all authority configured for (ChoiceAuthority ca : delegates.values()) { Choices tmp = ca.getBestMatch(field, text, null, locale); if (tmp.total > 0) { Set<Choice> mySet = new HashSet<Choice>(Arrays.asList(tmp.values)); choices.addAll(mySet); } } if (!choices.isEmpty()) { Choice[] results = new Choice[choices.size() - 1]; choices.toArray(results); return new Choices(results, 0, choices.size(), Choices.CF_UNCERTAIN, false); } } else { formName = dci.getInputFormNameByCollectionAndField(collection, field); return delegates.get(formName).getBestMatch(field, text, collection, locale); } } catch (DCInputsReaderException e) { log.error(e.getMessage(), e); } return new Choices(Choices.CF_NOTFOUND); }
/** * Returns the set of DC inputs used for a particular input form * * @param formName input form unique name * @return DC input set * @throws DCInputsReaderException if not found */ public DCInputSet getInputsByFormName(String formName) throws DCInputsReaderException { // check mini-cache, and return if match if (lastInputSet != null && lastInputSet.getFormName().equals(formName)) { return lastInputSet; } // cache miss - construct new DCInputSet List<List<Map<String, String>>> pages = formDefns.get(formName); if (pages == null) { throw new DCInputsReaderException("Missing the " + formName + " form"); } lastInputSet = new DCInputSet(formName, pages, valuePairs); return lastInputSet; }
setResult(sb.toString()); } catch (DCInputsReaderException dcrE) { throw new IOException(dcrE.getMessage(), dcrE);
throw new DCInputsReaderException("Form " + formName + " has no rows"); throw new DCInputsReaderException("No form definition found");
throw new IllegalStateException(e.getMessage(), e);
throw new DCInputsReaderException("No form definition found");
private void autoRegisterAuthorityFromInputReader() { try { DCInputsReader dcInputsReader = new DCInputsReader(); for (DCInputSet dcinputSet : dcInputsReader.getAllInputs(Integer.MAX_VALUE, 0)) { DCInput[][] dcinputs = dcinputSet.getFields(); for (DCInput[] dcrows : dcinputs) { for (DCInput dcinput : dcrows) { if (StringUtils.isNotBlank(dcinput.getPairsType()) || StringUtils.isNotBlank(dcinput.getVocabulary())) { String authorityName = dcinput.getPairsType(); if (StringUtils.isBlank(authorityName)) { authorityName = dcinput.getVocabulary(); } if (!StringUtils.equals(dcinput.getInputType(), "qualdrop_value")) { String fieldKey = makeFieldKey(dcinput.getSchema(), dcinput.getElement(), dcinput.getQualifier()); boolean req = ConfigurationManager .getBooleanProperty("authority.required." + fieldKey, false); controlled.put(fieldKey, true); isAuthorityRequired.put(fieldKey, req); } } } } } } catch (DCInputsReaderException e) { throw new IllegalStateException(e.getMessage(), e); } } }
public List<DCInputSet> getInputsBySubmissionName(String name) throws DCInputsReaderException { SubmissionConfig config; try { config = new SubmissionConfigReader().getSubmissionConfigByName(name); String formName = config.getSubmissionName(); if (formName == null) { throw new DCInputsReaderException("No form designated as default"); } List<DCInputSet> results = new ArrayList<DCInputSet>(); for (int idx = 0; idx < config.getNumberOfSteps(); idx++) { SubmissionStepConfig step = config.getStep(idx); if (SubmissionStepConfig.INPUT_FORM_STEP_NAME.equals(step.getType())) { results.add(getInputsByFormName(step.getId())); } } return results; } catch (SubmissionConfigReaderException e) { throw new DCInputsReaderException("No form designated as default", e); } }
/** * Returns the set of DC inputs used for a particular collection, or the * default set if no inputs defined for the collection * * @param collectionHandle collection's unique Handle * @return DC input set * @throws DCInputsReaderException if no default set defined * @throws ServletException */ public List<DCInputSet> getInputsByCollectionHandle(String collectionHandle) throws DCInputsReaderException { SubmissionConfig config; try { config = new SubmissionConfigReader().getSubmissionConfigByCollection(collectionHandle); String formName = config.getSubmissionName(); if (formName == null) { throw new DCInputsReaderException("No form designated as default"); } List<DCInputSet> results = new ArrayList<DCInputSet>(); for (int idx = 0; idx < config.getNumberOfSteps(); idx++) { SubmissionStepConfig step = config.getStep(idx); if (SubmissionStepConfig.INPUT_FORM_STEP_NAME.equals(step.getType())) { results.add(getInputsByFormName(step.getId())); } } return results; } catch (SubmissionConfigReaderException e) { throw new DCInputsReaderException("No form designated as default", e); } }
public String getInputFormNameByCollectionAndField(Collection collection, String field) throws DCInputsReaderException { List<DCInputSet> inputSets = getInputsByCollectionHandle(collection.getHandle()); for (DCInputSet inputSet : inputSets) { String[] tokenized = Utils.tokenize(field); String schema = tokenized[0]; String element = tokenized[1]; String qualifier = tokenized[2]; if (StringUtils.isBlank(qualifier)) { qualifier = null; } String standardized = Utils.standardize(schema, element, qualifier, "."); if (inputSet.isFieldPresent(standardized)) { return inputSet.getFormName(); } } throw new DCInputsReaderException("No field configuration found!"); }