Example #1
0
  @Override
  public List<EntityRecord> getEntityRecordsFromLookup(
      Long entityId, String lookupName, Map<String, Object> lookupMap, QueryParams queryParams) {
    EntityDto entity = getEntity(entityId);
    validateCredentialsForReading(entity);

    LookupDto lookup = getLookupByName(entityId, lookupName);
    List<FieldDto> fields = entityService.getEntityFields(entityId);
    Map<String, FieldDto> fieldMap = entityService.getLookupFieldsMapping(entityId, lookupName);

    MotechDataService service = getServiceForEntity(entity);

    try {
      LookupExecutor lookupExecutor = new LookupExecutor(service, lookup, fieldMap);

      Object result = lookupExecutor.execute(lookupMap, queryParams);

      if (lookup.isSingleObjectReturn()) {
        EntityRecord record = instanceToRecord(result, entity, fields, service);
        return (record == null) ? new ArrayList<EntityRecord>() : Collections.singletonList(record);
      } else {
        List instances = (List) result;
        return instancesToRecords(instances, entity, fields, service);
      }
    } catch (RuntimeException e) {
      throw new LookupExecutionException(e);
    }
  }
Example #2
0
  /**
   * Returns true if lookups are different, false otherwise. It compares only read-only lookups,
   * that created in the code by developer.
   *
   * @param entityId the id of entity
   * @param newLookups the newLookups defined in the code
   * @return true if lookups are different, false otherwise.
   */
  public boolean lookupsDiffer(Long entityId, List<LookupDto> newLookups) {
    List<LookupDto> existingLookups = entityService.getEntityLookups(entityId);
    Map<String, LookupDto> entityLookupsMappings = new HashMap<>();

    for (LookupDto entityLookup : existingLookups) {
      if (entityLookup.isReadOnly()) {
        entityLookupsMappings.put(entityLookup.getLookupName(), entityLookup);
      }
    }

    if (entityLookupsMappings.size() != newLookups.size()) {
      return true;
    }

    for (LookupDto lookup : newLookups) {
      if (!lookupEquals(lookup, entityLookupsMappings.get(lookup.getLookupName()))) {
        return true;
      }
    }

    return false;
  }
Example #3
0
  private void addEditableEntityLookups(MDSProcessorOutput output, EntityLookups entityLookups) {

    String entityClassName = entityLookups.getEntityClassName();
    List<LookupDto> lookups = getLookups(output, entityClassName);

    if (lookups == null) {
      lookups = new ArrayList<>();
      output.getLookupProcessorOutputs().put(entityClassName, lookups);
    }

    for (LookupDto lookup : entityLookups.getLookups()) {
      if (!jsonLookupService.exists(entityClassName, lookup.getLookupName())) {

        lookups.add(lookup);

        JsonLookupDto jsonLookup = new JsonLookupDto(entityClassName, lookup.getLookupName());
        jsonLookupService.createJsonLookup(jsonLookup);

        LOGGER.debug(
            "Added \"{}\" lookup for \"{}\" entity", lookup.getLookupName(), entityClassName);
      }
    }
  }
Example #4
0
 private boolean lookupEquals(LookupDto a, LookupDto b) {
   return a != null
       && b != null
       && // NO CHECKSTYLE Boolean expression complexity
       Objects.equals(a.getLookupName(), b.getLookupName())
       && Objects.equals(a.isSingleObjectReturn(), b.isSingleObjectReturn())
       && Objects.equals(a.isExposedViaRest(), b.isExposedViaRest())
       && Objects.equals(a.isReadOnly(), b.isReadOnly())
       && Objects.equals(a.getMethodName(), b.getMethodName())
       && Objects.equals(a.isReferenced(), b.isReferenced())
       && lookupFieldsEqual(a.getLookupFields(), b.getLookupFields());
 }