private Metadata newPathMetadata(String schemaCode) {
   String code = schemaCode + "_path";
   Metadata metadata = mock(Metadata.class, code);
   when(metadata.getLocalCode()).thenReturn("path");
   when(metadata.getCode()).thenReturn(code);
   when(metadata.getType()).thenReturn(MetadataValueType.STRING);
   return metadata;
 }
 private Metadata newAllAuthorizationsMetadata(String schemaCode) {
   String code = schemaCode + "_allauthorizations";
   Metadata metadata = mock(Metadata.class, code);
   when(metadata.getLocalCode()).thenReturn("allauthorizations");
   when(metadata.getCode()).thenReturn(code);
   when(metadata.getType()).thenReturn(MetadataValueType.STRING);
   return metadata;
 }
  private Metadata configureMetadataWithHierarchyDependency(
      Metadata metadata, MetadataSchemaTypes types, String code) {

    when(metadata.getCode()).thenReturn(code);
    when(metadata.getLocalCode()).thenReturn(code.split("_")[2]);
    MetadataValueCalculator metadataValueCalculator = mock(MetadataValueCalculator.class);
    List dependencies = Arrays.asList(SpecialDependencies.HIERARCHY);
    when(metadataValueCalculator.getDependencies()).thenReturn(dependencies);
    when(metadata.getDataEntry()).thenReturn(new CalculatedDataEntry(metadataValueCalculator));
    return metadata;
  }
  private Metadata givenReferenceToSchemaType(
      Metadata metadata, MetadataSchemaTypes types, String code, boolean childOf, String type) {
    when(metadata.getCode()).thenReturn(code);
    when(metadata.getLocalCode()).thenReturn(code.split("_")[2]);
    when(metadata.getType()).thenReturn(MetadataValueType.REFERENCE);

    AllowedReferences allowedReferences = new AllowedReferences(type, null);
    when(metadata.getAllowedReferences()).thenReturn(allowedReferences);
    when(types.getMetadata(code)).thenReturn(metadata);

    return metadata;
  }
Ejemplo n.º 5
0
  private void addPropertyForSingleValueMetadata(
      Set<String> orgfilter,
      String typeId,
      PropertiesImpl result,
      Metadata metadata,
      Object value,
      String propertyCode) {
    if (metadata.getType().isStringOrText() || metadata.getType() == MetadataValueType.REFERENCE) {
      addPropertyString(result, typeId, orgfilter, propertyCode, (String) value);

    } else if (metadata.getType() == MetadataValueType.BOOLEAN) {
      addPropertyBoolean(result, typeId, orgfilter, propertyCode, (Boolean) value);

    } else if (metadata.getType() == MetadataValueType.ENUM) {
      addPropertyEnum(result, typeId, orgfilter, propertyCode, (EnumWithSmallCode) value);

    } else if (metadata.getType() == MetadataValueType.NUMBER) {
      addPropertyDouble(result, typeId, orgfilter, propertyCode, (Double) value);

    } else if (metadata.getType() == MetadataValueType.DATE_TIME
        || metadata.getType() == MetadataValueType.DATE) {
      GregorianCalendar calendarValue = getGregorianCalendar(value);
      addPropertyDateTime(result, typeId, orgfilter, propertyCode, calendarValue);

    } else if (metadata.getType() == MetadataValueType.CONTENT) {
      addPropertyString(result, typeId, orgfilter, propertyCode, ((Content) value).getId());
    }
  }
Ejemplo n.º 6
0
  private void addPropertyForMultiValueMetadata(
      Set<String> orgfilter,
      String typeId,
      PropertiesImpl result,
      Metadata metadata,
      Object value,
      String propertyCode) {
    if (!((List) value).isEmpty()) {
      if (metadata.getType().isStringOrText()
          || metadata.getType() == MetadataValueType.REFERENCE) {
        addPropertyListString(result, typeId, orgfilter, propertyCode, (List<String>) value);

      } else if (metadata.getType() == MetadataValueType.ENUM) {
        addPropertyListEnum(
            result, typeId, orgfilter, propertyCode, (List<EnumWithSmallCode>) value);

      } else if (metadata.getType() == MetadataValueType.BOOLEAN) {
        addPropertyListBoolean(result, typeId, orgfilter, propertyCode, (List<Boolean>) value);

      } else if (metadata.getType() == MetadataValueType.NUMBER) {
        addPropertyListInteger(result, typeId, orgfilter, propertyCode, (List<Long>) value);

      } else if (metadata.getType() == MetadataValueType.DATE_TIME
          || metadata.getType() == MetadataValueType.DATE) {
        List<GregorianCalendar> calendarValues = new ArrayList<>();
        for (Object dateObject : (List<Object>) value) {
          calendarValues.add(getGregorianCalendar(dateObject));
        }
        addPropertyListDateTime(result, typeId, orgfilter, propertyCode, calendarValues);
      }
    }
  }
Ejemplo n.º 7
0
 private void addPropertiesForMetadatas(
     Record record, Set<String> orgfilter, String typeId, PropertiesImpl result) {
   for (Metadata metadata :
       modelLayerFactory
           .getMetadataSchemasManager()
           .getSchemaTypes(record.getCollection())
           .getSchema(record.getSchemaCode())
           .getMetadatas()) {
     Object value = record.get(metadata);
     String propertyCode = metadata.getCode();
     if (value != null) {
       if (!metadata.isMultivalue()) {
         addPropertyForSingleValueMetadata(
             orgfilter, typeId, result, metadata, value, propertyCode);
       } else {
         addPropertyForMultiValueMetadata(
             orgfilter, typeId, result, metadata, value, propertyCode);
       }
     }
   }
 }
  public ConditionTemplate metadatasHasAnalyzedValue(String value, List<Metadata> metadatas) {

    List<String> availableLanguages =
        modelLayerFactory.getCollectionsListManager().getCollectionLanguages(collection);
    LanguageDetectionManager languageDetectionManager =
        modelLayerFactory.getLanguageDetectionManager();

    String language =
        availableLanguages.size() == 1
            ? availableLanguages.get(0)
            : languageDetectionManager.tryDetectLanguage(value);
    List<Metadata> searchedMetadatas = new ArrayList<>();
    for (Metadata metadata : metadatas) {
      if (!availableLanguages.contains(language) || language == null) {
        for (String availableLanguage : availableLanguages) {
          searchedMetadatas.add(metadata.getSearchableMetadataWithLanguage(availableLanguage));
        }
      } else {
        searchedMetadatas.add(metadata.getSearchableMetadataWithLanguage(language));
      }
    }

    return ConditionTemplate.anyField(searchedMetadatas, query(value));
  }
Ejemplo n.º 9
0
  @Before
  public void setUp() throws Exception {
    when(textMetadata.getDataStoreCode()).thenReturn("textMetadata");
    when(textMetadata.getType()).thenReturn(MetadataValueType.STRING);

    when(referenceMetadata.getDataStoreCode()).thenReturn("referenceMetadata");
    when(referenceMetadata.getType()).thenReturn(MetadataValueType.REFERENCE);

    when(numberMetadata.getDataStoreCode()).thenReturn("numberMetadata");
    when(numberMetadata.getType()).thenReturn(MetadataValueType.NUMBER);

    when(booleanMetadata.getDataStoreCode()).thenReturn("booleanMetadata");
    when(booleanMetadata.getType()).thenReturn(MetadataValueType.BOOLEAN);

    when(dateMetadata.getDataStoreCode()).thenReturn("dateTimeMetadata");
    when(dateMetadata.getType()).thenReturn(MetadataValueType.DATE_TIME);

    when(contentMetadata.getDataStoreCode()).thenReturn("contentMetadata");
    when(contentMetadata.getType()).thenReturn(MetadataValueType.CONTENT);
  }