use of org.apache.flink.shaded.guava30.com.google.common.base.Strings in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method fillExtendedAttributes.
/**
* Fill extended attribute for given entity. Entity must be persisted first.
*
* @param mappedAttributes
* @param uid
* @param icAttributes
* @param dto
* @param create (is create or update entity situation)
* @param context
* @return
*/
@SuppressWarnings("unchecked")
protected IdmFormInstanceDto fillExtendedAttributes(List<SysSystemAttributeMappingDto> mappedAttributes, String uid, List<IcAttribute> icAttributes, DTO dto, boolean create, SynchronizationContext context) {
IdmFormInstanceDto formInstanceDto = new IdmFormInstanceDto();
IdmFormDefinitionDto formDefinitionDto = formService.getDefinition(context.getEntityType().getExtendedAttributeOwnerType());
formInstanceDto.setFormDefinition(formDefinitionDto);
mappedAttributes.stream().filter(attribute -> {
// Skip disabled attributes
// Only for extended attributes
boolean fastResult = !attribute.isDisabledAttribute() && attribute.isExtendedAttribute();
if (!fastResult) {
return false;
}
// Can be value set by attribute strategy?
return this.canSetValue(uid, attribute, dto, create);
}).forEach(attribute -> {
String attributeProperty = attribute.getIdmPropertyName();
Object transformedValue = getValueByMappedAttribute(attribute, icAttributes, context);
// Save to extended attribute
if (!formService.isFormable(dto.getClass())) {
String message = MessageFormat.format("Entity [{0}] is not instance of formable entity!", dto.getId());
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_ERROR_DURING_SYNC_ITEM, ImmutableMap.of("uid", uid, "message", message));
}
SystemEntityType entityType = context.getEntityType();
Assert.notNull(entityType, "Entity type is requierd!");
IdmFormAttributeDto defAttribute = formService.getDefinition(entityType.getExtendedAttributeOwnerType()).getMappedAttributeByCode(attributeProperty);
if (defAttribute == null) {
// eav definition could be changed
String message = MessageFormat.format("Form attribute definition [{0}] was not found!", attributeProperty);
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_ERROR_DURING_SYNC_ITEM, ImmutableMap.of("uid", uid, "message", message));
}
List<Serializable> values;
if (transformedValue instanceof List<?>) {
// TODO: Convert List GuardedStrings to Strings!
((List<?>) transformedValue).stream().forEach(value -> {
if (value != null && !(value instanceof Serializable)) {
String message = MessageFormat.format("Value [{0}] is not serializable for the attribute [{1}] and UID [{2}]!", value, attribute, uid);
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_ERROR_DURING_SYNC_ITEM, ImmutableMap.of("uid", uid, "message", message));
}
});
values = ((List<Serializable>) transformedValue);
} else {
// Convert GuardedString to string
values = Lists.newArrayList(transformedValue instanceof GuardedString ? ((GuardedString) transformedValue).asString() : (Serializable) transformedValue);
}
if (!context.isEntityDifferent()) {
List<IdmFormValueDto> previousValues = formService.getValues(dto.getId(), entityType.getEntityType(), defAttribute);
if (defAttribute.isConfidential() && previousValues != null) {
previousValues.forEach(formValue -> {
formValue.setValue(formService.getConfidentialPersistentValue(formValue));
});
}
List<IdmFormValueDto> newValues = values.stream().filter(value -> value != null).map(value -> {
IdmFormValueDto formValue = new IdmFormValueDto(defAttribute);
formValue.setValue(value);
return formValue;
}).collect(Collectors.toList());
boolean isEavValuesSame = this.isEavValuesSame(newValues, previousValues);
if (!isEavValuesSame) {
context.setIsEntityDifferent(true);
addToItemLog(context.getLogItem(), MessageFormat.format("Value of EAV attribute [{0}] was changed. First change was detected -> entity in IdM will be updated.", attributeProperty));
}
}
if (context.isEntityDifferent()) {
List<IdmFormValueDto> formValues = values.stream().map(value -> {
IdmFormValueDto formValue = new IdmFormValueDto(defAttribute);
formValue.setValue(value);
return formValue;
}).collect(Collectors.toList());
formInstanceDto.getValues().addAll(formValues);
}
});
return formInstanceDto;
}
use of org.apache.flink.shaded.guava30.com.google.common.base.Strings in project fdb-record-layer by FoundationDB.
the class FDBRecordStoreTest method prefixPrimaryKeysWithNullByteAfterPrefix.
/**
* If there are two primary keys that overlap in the just the right way, then one can have the representation
* of one record's primary key be a strict prefix of the other record's. With older versions of the Record Layer,
* this could lead to problems where attempting to load the record with the shorter key would also read data for
* the record with the longer key. See <a href="https://github.com/FoundationDB/fdb-record-layer/issues/782">Issue #782</a>.
*
* <p>
* This test is parameterized by format version because the fix involves being more particular about the range that
* is scanned. In particular, the scan range is now only over those keys which are strict prefixes of the primary
* key. This is fine as long as there aren't any data stored at that key. Prior to {@link FDBRecordStore#SAVE_UNSPLIT_WITH_SUFFIX_FORMAT_VERSION},
* there could be data in that key was not true if {@code splitLongRecords} was {@code false}. Parameterizing here
* tests those older configurations.
* </p>
*
* @param formatVersion format version to use when running the test
* @param splitLongRecords whether the test should split long records or not
*/
@ParameterizedTest(name = "prefixPrimaryKeysWithNullByteAfterPrefix [formatVersion = {0}, splitLongRecords = {1}]")
@MethodSource("formatVersionAndSplitArgs")
public void prefixPrimaryKeysWithNullByteAfterPrefix(int formatVersion, boolean splitLongRecords) throws Exception {
final RecordMetaDataHook hook = metaData -> {
metaData.setSplitLongRecords(splitLongRecords);
metaData.getRecordType("MySimpleRecord").setPrimaryKey(field("str_value_indexed"));
};
final FDBRecordStore.Builder storeBuilder;
// The primary key for record1 is a prefix of the primary key for record2, and the first byte in record2's primary
// key is a null byte. Because FDB's Tuple layer null terminates its representation of strings, this means that
// the keys used to store record1 forms a prefix of the keys storing record2. However, the null byte should be
// escaped in such a way that it is possible to read only the keys for record1. This is necessary to properly load
// the record by primary key.
final TestRecords1Proto.MySimpleRecord record1 = TestRecords1Proto.MySimpleRecord.newBuilder().setStrValueIndexed("foo").setNumValue3Indexed(1066).build();
final TestRecords1Proto.MySimpleRecord record2 = TestRecords1Proto.MySimpleRecord.newBuilder().setStrValueIndexed("foo\0bar").setNumValue3Indexed(1415).build();
// Save the two records
try (FDBRecordContext context = openContext()) {
uncheckedOpenSimpleRecordStore(context, hook);
storeBuilder = recordStore.asBuilder().setFormatVersion(formatVersion);
final FDBRecordStore store = storeBuilder.create();
store.saveRecord(record1);
store.saveRecord(record2);
commit(context);
}
// Load by scanning records
try (FDBRecordContext context = openContext()) {
final FDBRecordStore store = storeBuilder.setContext(context).open();
final List<FDBStoredRecord<Message>> records = store.scanRecords(null, ScanProperties.FORWARD_SCAN).asList().get();
assertThat(records, hasSize(2));
assertEquals(record1, records.get(0).getRecord());
assertEquals(record2, records.get(1).getRecord());
}
// Load by primary key
try (FDBRecordContext context = openContext()) {
final FDBRecordStore store = storeBuilder.setContext(context).open();
FDBStoredRecord<Message> storedRecord1 = store.loadRecord(Tuple.from(record1.getStrValueIndexed()));
assertNotNull(storedRecord1, "record1 was missing");
assertEquals(record1, storedRecord1.getRecord());
FDBStoredRecord<Message> storedRecord2 = store.loadRecord(Tuple.from(record2.getStrValueIndexed()));
assertNotNull(storedRecord2, "record2 was missing");
assertEquals(record2, storedRecord2.getRecord());
}
// Load by query
try (FDBRecordContext context = openContext()) {
final FDBRecordStore store = storeBuilder.setContext(context).open();
final RecordQuery query = RecordQuery.newBuilder().setRecordType("MySimpleRecord").setFilter(Query.field("num_value_3_indexed").equalsParameter("num")).build();
final RecordQueryPlan plan = store.planQuery(query);
assertThat(plan, indexScan(allOf(indexName("MySimpleRecord$num_value_3_indexed"), bounds(hasTupleString("[EQUALS $num]")))));
// Record 1
List<FDBQueriedRecord<Message>> record1List = plan.execute(store, EvaluationContext.forBinding("num", 1066)).asList().get();
assertThat(record1List, hasSize(1));
FDBQueriedRecord<Message> queriedRecord1 = record1List.get(0);
assertEquals(record1, queriedRecord1.getRecord());
// Record 2
List<FDBQueriedRecord<Message>> record2List = plan.execute(store, EvaluationContext.forBinding("num", 1415)).asList().get();
assertThat(record2List, hasSize(1));
FDBQueriedRecord<Message> queriedRecord2 = record2List.get(0);
assertEquals(record2, queriedRecord2.getRecord());
}
}
use of org.apache.flink.shaded.guava30.com.google.common.base.Strings in project timbuctoo by HuygensING.
the class RelatedDatableRangeFacetDescription method filter.
@Override
@SuppressWarnings("unchecked")
public void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facets) {
Optional<FacetValue> first = facets.stream().filter(facetValue -> Objects.equals(facetValue.getName(), facetName)).findFirst();
if (!first.isPresent()) {
return;
}
FacetValue facetValue = first.get();
if (!(facetValue instanceof DateRangeFacetValue)) {
return;
}
// pad the strings to make them parsable
String lowerLimitString = Strings.padStart("" + ((DateRangeFacetValue) facetValue).getLowerLimit(), 8, '0').substring(0, 4);
String upperLimitString = Strings.padStart("" + ((DateRangeFacetValue) facetValue).getUpperLimit(), 8, '0').substring(0, 4);
try {
Range<Date> range = Range.closed(FILTER_FORMAT.parse(lowerLimitString), FILTER_FORMAT.parse(upperLimitString));
graphTraversal.where(__.bothE(relations).otherV().has(propertyName, P.test((o1, o2) -> {
Datable datable = getDatable("" + o1);
if (!datable.isValid()) {
return false;
}
Range<Date> range1 = (Range<Date>) o2;
return range1.contains(datable.getFromDate()) || range1.contains(datable.getToDate());
}, range)));
} catch (ParseException e) {
LOG.error("Cannot parse date", e);
}
}
use of org.apache.flink.shaded.guava30.com.google.common.base.Strings in project arctic-sea by 52North.
the class AbstractCapabilitiesBaseTypeDecoder method parseMetadata.
// private Set<OwsDomainMetadata> parseDomainMetadata(DomainMetadataType[]
// metadata) {
// return
// Optional.ofNullable(metadata).map(Arrays::stream).orElseGet(Stream::empty).map(this::parseDomainMetadata)
// .filter(Objects::nonNull).collect(toSet());
// }
private OwsMetadata parseMetadata(MetadataType metadata) {
if (metadata == null) {
return null;
}
URI href = Optional.ofNullable(metadata.getHref()).map(Strings::emptyToNull).map(URI::create).orElse(null);
URI role = Optional.ofNullable(metadata.getRole()).map(Strings::emptyToNull).map(URI::create).orElse(null);
URI arcrole = Optional.ofNullable(metadata.getArcrole()).map(Strings::emptyToNull).map(URI::create).orElse(null);
Show show = Optional.ofNullable(metadata.getShow()).map(Object::toString).map(Show::valueOf).orElse(null);
Actuate actuate = Optional.ofNullable(metadata.getActuate()).map(Object::toString).map(Actuate::valueOf).orElse(null);
URI about = Optional.ofNullable(metadata.getAbout()).map(Strings::emptyToNull).map(URI::create).orElse(null);
String title = metadata.getTitle();
return new OwsMetadata(href, role, arcrole, title, show, actuate, about);
}
use of org.apache.flink.shaded.guava30.com.google.common.base.Strings in project arctic-sea by 52North.
the class AbstractCapabilitiesBaseTypeDecoder method parse.
private <T extends OwsDomainMetadata> T parse(BiFunction<URI, String, T> fun, DomainMetadataType metadata) {
if (metadata == null) {
return null;
}
URI reference = Optional.ofNullable(metadata.getReference()).map(Strings::emptyToNull).map(URI::create).orElse(null);
String value = metadata.getStringValue();
return fun.apply(reference, value);
}
Aggregations