private Collection<FieldTypeEntry> getFieldTypeEntries(RecordType recordType) throws RepositoryException, InterruptedException { // Wrap the list as an array list since we don't know if the collection will actually support the .addAll() methodq Collection<FieldTypeEntry> fieldTypeEntries = new ArrayList<FieldTypeEntry>(recordType.getFieldTypeEntries()); Map<SchemaId, Long> supertypes = recordType.getSupertypes(); for (Entry<SchemaId, Long> supertypeEntry: supertypes.entrySet()) { RecordType supertypeRecordType = typeManager.getRecordTypeById(supertypeEntry.getKey(), supertypeEntry.getValue()); fieldTypeEntries.addAll(getFieldTypeEntries(supertypeRecordType)); } return fieldTypeEntries; }
@Override public Collection<FieldTypeEntry> getFieldTypesForRecordType(RecordType recordType, boolean includeSupertypes) throws RecordTypeNotFoundException, TypeException, RepositoryException, InterruptedException { if (!includeSupertypes) { return recordType.getFieldTypeEntries(); } else { // Pairs of record type id and version Map<Pair<SchemaId, Long>, RecordType> recordSupertypeMap = Maps.newHashMap(); collectRecordSupertypes(Pair.create(recordType.getId(), recordType.getVersion()), recordSupertypeMap); // We use a map of SchemaId to FieldTypeEntry so that we can let mandatory field type entries // for the same field type override non-mandatory versions Map<SchemaId, FieldTypeEntry> fieldTypeMap = Maps.newHashMap(); for (Pair<SchemaId, Long> recordSuperTypePair : recordSupertypeMap.keySet()) { RecordType superRecordType = recordSupertypeMap.get(recordSuperTypePair); for (FieldTypeEntry fieldTypeEntry : superRecordType.getFieldTypeEntries()) { SchemaId fieldTypeId = fieldTypeEntry.getFieldTypeId(); if (fieldTypeMap.containsKey(fieldTypeId)) { // Only overwrite an existing entry if we have one that is mandatory if (fieldTypeEntry.isMandatory()) { fieldTypeMap.put(fieldTypeId, fieldTypeEntry); } } else { fieldTypeMap.put(fieldTypeId, fieldTypeEntry); } } } return fieldTypeMap.values(); } }
@Override public Collection<FieldTypeEntry> getFieldTypesForRecordType(RecordType recordType, boolean includeSupertypes) throws RepositoryException, InterruptedException { if (!includeSupertypes) { return recordType.getFieldTypeEntries(); } else { // Pairs of record type id and version Map<Pair<SchemaId, Long>, RecordType> recordSupertypeMap = Maps.newHashMap(); collectRecordSupertypes(Pair.create(recordType.getId(), recordType.getVersion()), recordSupertypeMap); // We use a map of SchemaId to FieldTypeEntry so that we can let mandatory field type entries // for the same field type override non-mandatory versions Map<SchemaId, FieldTypeEntry> fieldTypeMap = Maps.newHashMap(); for (Pair<SchemaId, Long> recordSuperTypePair : recordSupertypeMap.keySet()) { RecordType superRecordType = recordSupertypeMap.get(recordSuperTypePair); for (FieldTypeEntry fieldTypeEntry : superRecordType.getFieldTypeEntries()) { SchemaId fieldTypeId = fieldTypeEntry.getFieldTypeId(); if (fieldTypeMap.containsKey(fieldTypeId)) { // Only overwrite an existing entry if we have one that is mandatory if (fieldTypeEntry.isMandatory()) { fieldTypeMap.put(fieldTypeId, fieldTypeEntry); } } else { fieldTypeMap.put(fieldTypeId, fieldTypeEntry); } } } return fieldTypeMap.values(); } }
private boolean updateFieldTypeEntries(Put put, Long newRecordTypeVersion, RecordType recordType, RecordType latestRecordType) throws FieldTypeNotFoundException, TypeException { boolean changed = false; Collection<FieldTypeEntry> latestFieldTypeEntries = latestRecordType.getFieldTypeEntries(); // Update FieldTypeEntries for (FieldTypeEntry fieldTypeEntry : recordType.getFieldTypeEntries()) { FieldTypeEntry latestFieldTypeEntry = latestRecordType.getFieldTypeEntry(fieldTypeEntry.getFieldTypeId()); if (!fieldTypeEntry.equals(latestFieldTypeEntry)) { putFieldTypeEntry(newRecordTypeVersion, put, fieldTypeEntry); changed = true; } latestFieldTypeEntries.remove(latestFieldTypeEntry); } // Remove remaining FieldTypeEntries for (FieldTypeEntry fieldTypeEntry : latestFieldTypeEntries) { put.add(TypeCf.FIELDTYPE_ENTRY.bytes, fieldTypeEntry.getFieldTypeId().getBytes(), newRecordTypeVersion, DELETE_MARKER); changed = true; } return changed; }
public AvroRecordType convert(RecordType recordType) { AvroRecordType avroRecordType = new AvroRecordType(); avroRecordType.setId(convert(recordType.getId())); avroRecordType.setName(convert(recordType.getName())); Long version = recordType.getVersion(); if (version != null) { avroRecordType.setVersion(version); } Collection<FieldTypeEntry> fieldTypeEntries = recordType.getFieldTypeEntries(); avroRecordType.setFieldTypeEntries(new ArrayList<AvroFieldTypeEntry>(fieldTypeEntries.size())); for (FieldTypeEntry fieldTypeEntry : fieldTypeEntries) { avroRecordType.getFieldTypeEntries().add(convert(fieldTypeEntry)); } Set<Entry<SchemaId, Long>> supertypeEntries = recordType.getSupertypes().entrySet(); avroRecordType.setSupertypes(new ArrayList<AvroSupertype>(supertypeEntries.size())); for (Entry<SchemaId, Long> supertypeEntry : supertypeEntries) { avroRecordType.getSupertypes().add(convert(supertypeEntry)); } return avroRecordType; }
Set<FieldTypeEntry> oldFieldTypeEntries = new HashSet<FieldTypeEntry>(oldRecordType.getFieldTypeEntries()); Set<FieldTypeEntry> newFieldTypeEntries = new HashSet<FieldTypeEntry>(newRecordType.getFieldTypeEntries()); if (!newFieldTypeEntries.equals(oldFieldTypeEntries)) { updated = true; oldRecordType.getFieldTypeEntries().clear();
for (FieldTypeEntry fte : recordType.getFieldTypeEntries()) { FieldType fieldType = null; try {
private void validateRecord(Record record, Record originalRecord, RecordType recordType, FieldTypes fieldTypes) throws TypeException, InvalidRecordException, InterruptedException { // Check mandatory fields Collection<FieldTypeEntry> fieldTypeEntries = recordType.getFieldTypeEntries(); List<QName> fieldsToDelete = record.getFieldsToDelete(); for (FieldTypeEntry fieldTypeEntry : fieldTypeEntries) { if (fieldTypeEntry.isMandatory()) { FieldType fieldType = fieldTypes.getFieldType(fieldTypeEntry.getFieldTypeId()); QName fieldName = fieldType.getName(); if (fieldsToDelete.contains(fieldName)) { throw new InvalidRecordException("Field: '" + fieldName + "' is mandatory.", record.getId()); } if (!record.hasField(fieldName) && !originalRecord.hasField(fieldName)) { throw new InvalidRecordException("Field: '" + fieldName + "' is mandatory.", record.getId()); } } } }
Collection<FieldTypeEntry> fieldTypeEntries = recordType.getFieldTypeEntries(); for (FieldTypeEntry fieldTypeEntry : fieldTypeEntries) { putFieldTypeEntry(recordTypeVersion, put, fieldTypeEntry);
private void validateRecord(Record record, Record originalRecord, RecordType recordType) throws TypeException, InvalidRecordException, InterruptedException, RepositoryException { // Check mandatory fields Collection<FieldTypeEntry> fieldTypeEntries = recordType.getFieldTypeEntries(); List<QName> fieldsToDelete = record.getFieldsToDelete(); for (FieldTypeEntry fieldTypeEntry : fieldTypeEntries) { if (fieldTypeEntry.isMandatory()) { FieldType fieldType = getTypeManager().getFieldTypeById(fieldTypeEntry.getFieldTypeId()); QName fieldName = fieldType.getName(); if (fieldsToDelete.contains(fieldName)) { throw new InvalidRecordException("Field: '" + fieldName + "' is mandatory.", record.getId()); } if (!record.hasField(fieldName) && !originalRecord.hasField(fieldName)) { throw new InvalidRecordException("Field: '" + fieldName + "' is mandatory.", record.getId()); } } } }
public static ObjectNode toJson(RecordType recordType, WriteOptions options, Namespaces namespaces, boolean includeName) { ObjectNode rtNode = JsonNodeFactory.instance.objectNode(); rtNode.put("id", recordType.getId().toString()); if (includeName) { rtNode.put("name", QNameConverter.toJson(recordType.getName(), namespaces)); } ArrayNode fieldsNode = rtNode.putArray("fields"); for (FieldTypeEntry entry : recordType.getFieldTypeEntries()) { ObjectNode entryNode = fieldsNode.addObject(); entryNode.put("id", entry.getFieldTypeId().toString()); entryNode.put("mandatory", entry.isMandatory()); } rtNode.put("version", recordType.getVersion()); ArrayNode supertypesNode = rtNode.putArray("supertypes"); for (Map.Entry<SchemaId, Long> supertype : recordType.getSupertypes().entrySet()) { ObjectNode entryNode = supertypesNode.addObject(); entryNode.put("id", supertype.getKey().toString()); entryNode.put("version", supertype.getValue()); } return rtNode; }