protected List<RegistrationSectionData> getRegistrationData(
      List<AppDescriptor> regAppDescriptors, final DataContextWrapper dataContext) {

    if (CollectionUtils.isEmpty(regAppDescriptors)) {
      throw new APIException("No Registration App instance enabled.");
      // TODO Check what REALLY happens by default when there are no reg apps around.
    }
    if (regAppDescriptors.size() > 1) {
      // TODO Check whether this is possible
      throw new APIException("Multiple Registration App instances enabled at the same time.");
    }
    final AppDescriptor regAppDesc = regAppDescriptors.get(0);

    List<RegistrationSectionData> sections = new ArrayList<RegistrationSectionData>();

    // First: filling the registration data structure
    RegistrationDataHelper dataHelper = new RegistrationDataHelper();
    try {
      sections = dataHelper.getSectionsFromConfig(regAppDesc.getConfig());
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    // Second: fetching the registration data
    for (RegistrationSectionData section : sections) {
      section.fetchData(dataContext);
      Extension linkExtension = new Extension();
      linkExtension.setLabel("general.edit");
      linkExtension.setType("link");
      linkExtension.setUrl(
          "registrationapp/editSection.page?patientId={{patient.patientId}}&sectionId="
              + section.getId()
              + "&appId="
              + regAppDesc.getId());
      /*
       * We don't allow edit links for sections where obs-type fields are involved.
       * This is because registration app's editSection.gsp doesn't handle them
       * 		and it doesn't actually fail on them either, giving the impression that everything was saved as expected.
       */
      if (!section.isWithObs()) {
        section.setLinkExtension(linkExtension);
      }
    }

    return sections;
  }
コード例 #2
0
  private void validate(Extension extension) {
    Set<ConstraintViolation<Extension>> constraintViolations = validator.validate(extension);
    if (!constraintViolations.isEmpty())
      throw new IllegalArgumentException(constraintViolations.iterator().next().getMessage());

    if (this.extensions.contains(extension))
      throw new IllegalArgumentException("Extension already exists: " + extension.getId());
  }