/**
  * Enrich the procedure description.
  *
  * @param desc the description
  * @param procedure the procedure
  * @param version the version
  * @param format the format
  * @param cache the procedure cache
  * @param language the language
  * @param session the session
  * @see HibernateProcedureEnrichment
  * @throws OwsExceptionReport if the enrichment fails
  */
 private void enrich(
     SosProcedureDescription desc,
     Procedure procedure,
     String version,
     String format,
     TimePeriod validTime,
     Map<String, Procedure> cache,
     Locale language,
     Session session)
     throws OwsExceptionReport {
   ProcedureDescriptionEnrichments enrichments =
       ProcedureDescriptionEnrichments.create()
           .setIdentifier(procedure.getIdentifier())
           .setVersion(version)
           .setDescription(desc)
           .setProcedureDescriptionFormat(format)
           .setSession(session)
           .setValidTime(validTime)
           .setProcedureCache(cache)
           .setConverter(this)
           .setLanguage(language);
   if (desc instanceof SensorML && ((SensorML) desc).isWrapper()) {
     enrichments.setDescription(desc).createValidTimeEnrichment().enrich();
     for (AbstractProcess abstractProcess : ((SensorML) desc).getMembers()) {
       enrichments.setDescription(abstractProcess).enrichAll();
     }
   } else {
     enrichments.enrichAll();
   }
 }
 /**
  * Create procedure description from file, single XML text or generate
  *
  * @param procedure Hibernate procedure entity
  * @param requestedDescriptionFormat Requested procedure descriptionFormat
  * @param requestedServiceVersion Requested SOS version
  * @param loadedProcedures Loaded procedure hierarchy (passed to recursive requests to avoid
  *     multiple queries)
  * @param session Hibernate session
  * @return created SosProcedureDescription
  * @throws OwsExceptionReport If an error occurs
  */
 public SosProcedureDescription createSosProcedureDescription(
     Procedure procedure,
     String requestedDescriptionFormat,
     String requestedServiceVersion,
     Map<String, Procedure> loadedProcedures,
     Locale i18n,
     Session session)
     throws OwsExceptionReport {
   if (procedure == null) {
     throw new NoApplicableCodeException()
         .causedBy(new IllegalArgumentException("Parameter 'procedure' should not be null!"))
         .setStatus(HTTPStatus.INTERNAL_SERVER_ERROR);
   }
   checkOutputFormatWithDescriptionFormat(
       procedure.getIdentifier(), procedure, requestedDescriptionFormat, getFormat(procedure));
   SosProcedureDescription desc =
       create(procedure, requestedDescriptionFormat, null, i18n, session).orNull();
   if (desc != null) {
     enrich(
         desc,
         procedure,
         requestedServiceVersion,
         requestedDescriptionFormat,
         null,
         loadedProcedures,
         i18n,
         session);
     if (!requestedDescriptionFormat.equals(desc.getDescriptionFormat())) {
       desc = convert(desc.getDescriptionFormat(), requestedDescriptionFormat, desc);
       desc.setDescriptionFormat(requestedDescriptionFormat);
     }
   }
   return desc;
 }
 /**
  * Create procedure description from XML text stored in ValidProcedureTime table
  *
  * @param procedure Hibernate procedure entity
  * @param vpt Hibernate ValidProcedureTime entity
  * @param version Requested SOS version
  * @param session Hibernate session
  * @return created SosProcedureDescription
  * @throws OwsExceptionReport If an error occurs
  */
 public SosProcedureDescription createSosProcedureDescriptionFromValidProcedureTime(
     Procedure procedure,
     String requestedDescriptionFormat,
     ValidProcedureTime vpt,
     String version,
     Locale i18n,
     Session session)
     throws OwsExceptionReport {
   if (vpt != null) {
     checkOutputFormatWithDescriptionFormat(
         procedure.getIdentifier(), vpt, requestedDescriptionFormat, getFormat(vpt));
   } else {
     checkOutputFormatWithDescriptionFormat(
         procedure.getIdentifier(), procedure, requestedDescriptionFormat, getFormat(procedure));
   }
   Optional<SosProcedureDescription> description =
       create(procedure, requestedDescriptionFormat, vpt, i18n, session);
   if (description.isPresent()) {
     enrich(
         description.get(),
         procedure,
         version,
         requestedDescriptionFormat,
         getValidTime(vpt),
         null,
         i18n,
         session);
     if (!requestedDescriptionFormat.equals(description.get().getDescriptionFormat())) {
       SosProcedureDescription converted =
           convert(
               description.get().getDescriptionFormat(),
               requestedDescriptionFormat,
               description.get());
       converted.setDescriptionFormat(requestedDescriptionFormat);
       return converted;
     }
   }
   return description.orNull();
 }
 @Override
 public boolean apply(Procedure p) {
   return Strings.isNullOrEmpty(p.getDescriptionFile());
 }