private Map<QName, Object> filterMutableFields(Map<QName, Object> fields, FieldTypes fieldTypes) throws RecordException, TypeException, InterruptedException { Map<QName, Object> mutableFields = new HashMap<QName, Object>(); for (Entry<QName, Object> field : fields.entrySet()) { FieldType fieldType = fieldTypes.getFieldType(field.getKey()); if (Scope.VERSIONED_MUTABLE.equals(fieldType.getScope())) { mutableFields.put(field.getKey(), field.getValue()); } } return mutableFields; }
private void copyUnspecifiedFields(FieldType userFieldType, FieldType latestFieldType) throws FieldTypeUpdateException { if (userFieldType.getScope() == null) { userFieldType.setScope(latestFieldType.getScope()); } if (userFieldType.getValueType() == null) { userFieldType.setValueType(latestFieldType.getValueType()); } }
/** * Removes any versioned information from the supplied record object. */ public static void reduceToNonVersioned(Record record, Set<QName> fields, TypeManager typeManager) throws RepositoryException, InterruptedException { if (record.getVersion() == null) { // The record has no versions so there should be no versioned fields in it return; } Iterator<Map.Entry<QName, Object>> fieldsIt = record.getFields().entrySet().iterator(); while (fieldsIt.hasNext()) { Map.Entry<QName, Object> entry = fieldsIt.next(); if (fields != null && !fields.contains(entry.getKey())) { fieldsIt.remove(); } else if (typeManager.getFieldTypeByName(entry.getKey()).getScope() != Scope.NON_VERSIONED) { fieldsIt.remove(); } } // Remove versioned record type info record.setRecordType(Scope.VERSIONED, (QName) null, null); record.setRecordType(Scope.VERSIONED_MUTABLE, (QName) null, null); }
public static Map<Scope, Set<FieldType>> getFieldTypeAndScope(Set<SchemaId> fieldIds, FieldFilter fieldFilter, TypeManager typeManager) throws RepositoryException, InterruptedException { // Could be written more elegantly using Multimaps.index, but we want to limit dependencies Map<Scope, Set<FieldType>> result = new EnumMap<Scope, Set<FieldType>>(Scope.class); for (Scope scope : Scope.values()) { result.put(scope, new HashSet<FieldType>()); } for (SchemaId fieldId : fieldIds) { FieldType fieldType; try { fieldType = typeManager.getFieldTypeById(fieldId); } catch (FieldTypeNotFoundException e) { // A field whose field type does not exist: skip it continue; } if (fieldFilter.accept(fieldType)) { result.get(fieldType.getScope()).add(fieldType); } } return result; }
/** * Removes any versioned information from the supplied record object. * * <p>This method can be removed once we have a repository method that is able to filter this when loading * the record. */ public static void reduceToNonVersioned(IdRecord record, TypeManager typeManager) throws RepositoryException, InterruptedException { if (record.getVersion() == null) { // The record has no versions so there should be no versioned fields in it return; } // Remove all non-versioned fields from the record Map<SchemaId, QName> mapping = record.getFieldIdToNameMapping(); Iterator<Map.Entry<SchemaId, QName>> it = mapping.entrySet().iterator(); while (it.hasNext()) { Map.Entry<SchemaId, QName> entry = it.next(); if (typeManager.getFieldTypeById(entry.getKey()).getScope() != Scope.NON_VERSIONED) { record.delete(entry.getValue(), false); it.remove(); } } // Remove versioned record type info record.setRecordType(Scope.VERSIONED, (QName) null, null); record.setRecordType(Scope.VERSIONED_MUTABLE, (QName) null, null); } }
/** * Returns true if the given FieldType is a version tag. */ public static boolean isVersionTag(FieldType fieldType) { String namespace = fieldType.getName().getNamespace(); return (fieldType.getScope() == Scope.NON_VERSIONED && fieldType.getValueType().getBaseName().equals("LONG") && namespace != null && namespace.equals(NAMESPACE) /* namespace is typically the longest string, therefore compare it last */ && !fieldType.getName().getName().equals("last")); /* filter out 'last' vtag, it should not be custom assigned */ }
private void checkImmutableFieldsCorrespond(FieldType userFieldType, FieldType latestFieldType) throws FieldTypeUpdateException { if (!userFieldType.getValueType().equals(latestFieldType.getValueType())) { throw new FieldTypeUpdateException("Changing the valueType of a fieldType '" + latestFieldType.getId() + "' (current name: " + latestFieldType.getName() + ") is not allowed; old '" + latestFieldType.getValueType() + "' new '" + userFieldType.getValueType() + "'"); } if (!userFieldType.getScope().equals(latestFieldType.getScope())) { throw new FieldTypeUpdateException("Changing the scope of a fieldType '" + latestFieldType.getId() + "' (current name: " + latestFieldType.getName() + ") is not allowed; old '" + latestFieldType.getScope() + "' new '" + userFieldType.getScope() + "'"); } }
fieldsByScope.get(fieldType.getScope()).put(field.getKey(), field.getValue()); } else { undeterminedFields.put(field.getKey(), field.getValue());
scopes.get(versionToRead).add(lastDecodedField.type.getScope()); if (lastDecodedField.metadata != null) { record.setMetadata(lastDecodedField.type.getName(), lastDecodedField.metadata);
@Override public FieldType create() throws RepositoryException, InterruptedException { FieldType fieldType = buildFieldType(); // Apply defaults if (fieldType.getValueType() == null) { fieldType.setValueType(typeManager.getValueType("STRING")); } if (fieldType.getScope() == null) { fieldType.setScope(Scope.NON_VERSIONED); } return typeManager.createFieldType(fieldType); }
if (fieldType.getScope() == Scope.VERSIONED_MUTABLE) { throw new RuntimeException("Field metadata is currently not supported for versioned-mutable fields.");
fieldTypeEntriesByScope.get(fieldType.getScope()).add(new Pair<FieldTypeEntry, FieldType>(fte, fieldType)); } else { failedFieldTypes.add(fte.getFieldTypeId());
public static ObjectNode toJson(FieldType fieldType, Namespaces namespaces, boolean includeName) { ObjectNode fieldNode = JsonNodeFactory.instance.objectNode(); fieldNode.put("id", fieldType.getId().toString()); if (includeName) { fieldNode.put("name", QNameConverter.toJson(fieldType.getName(), namespaces)); } fieldNode.put("scope", fieldType.getScope().toString().toLowerCase()); fieldNode.put("valueType", ValueTypeNSConverter.toJson(fieldType.getValueType().getName(), namespaces)); return fieldNode; } }
ArgumentValidator.notNull(fieldType.getName(), "fieldType.name"); ArgumentValidator.notNull(fieldType.getValueType(), "fieldType.valueType"); ArgumentValidator.notNull(fieldType.getScope(), "fieldType.scope"); put.add(TypeCf.DATA.bytes, TypeColumn.FIELDTYPE_VALUETYPE.bytes, encodeValueType(fieldType.getValueType())); put.add(TypeCf.DATA.bytes, TypeColumn.FIELDTYPE_SCOPE.bytes, Bytes .toBytes(fieldType.getScope().name())); put.add(TypeCf.DATA.bytes, TypeColumn.FIELDTYPE_NAME.bytes, nameBytes);
if (fieldTypes.getFieldType(field).getScope() != Scope.NON_VERSIONED) { throw new RepositoryException("Deleting records with versioned or versioned-mutable fields " + "is not supported when authorization is active.");
public AvroFieldType convert(FieldType fieldType) { AvroFieldType avroFieldType = new AvroFieldType(); avroFieldType.setId(convert(fieldType.getId())); avroFieldType.setName(convert(fieldType.getName())); avroFieldType.setValueType(convert(fieldType.getValueType())); avroFieldType.setScope(convert(fieldType.getScope())); return avroFieldType; }
if (!scopes.contains(fieldType.getScope())) { match.match = false; return match;
if (fieldType.getScope() != Scope.NON_VERSIONED) { throw new JsonFormatException("vtag fields should be in the non-versioned scope");