private static void requireIdOfMatchingType(ReferenceDataType referenceType, DocumentId id) { final String expectedTypeName = referenceType.getTargetType().getName(); if (!id.getDocType().equals(expectedTypeName)) { throw new IllegalArgumentException(String.format( "Can't assign document ID '%s' (of type '%s') to reference of document type '%s'", id, id.getDocType(), expectedTypeName)); } }
public DocumentType readDocumentType(DocumentId docId) { return getDocumentTypeFromString(docId.getDocType(), typeManager); }
private void internalSetId(DocumentId id, DocumentType docType) { if (id != null && id.hasDocType() && docType != null && !id.getDocType().equals(docType.getName())) { throw new IllegalArgumentException("Trying to set a document id (type " + id.getDocType() + ") that doesn't match the document type (" + getDataType().getName() + ")."); } docId = id; }
public Object evaluate(DocumentOperation op) { DocumentType doct; if (op instanceof DocumentPut) { doct = ((DocumentPut)op).getDocument().getDataType(); } else if (op instanceof DocumentUpdate) { doct = ((DocumentUpdate)op).getDocumentType(); } else if (op instanceof DocumentRemove) { DocumentRemove removeOp = (DocumentRemove)op; return (removeOp.getId().getDocType().equals(type) ? op : Boolean.FALSE); } else if (op instanceof DocumentGet) { DocumentGet getOp = (DocumentGet)op; return (getOp.getId().getDocType().equals(type) ? op : Boolean.FALSE); } else { throw new IllegalStateException("Document class '" + op.getClass().getName() + "' is not supported."); } return doct.isA(this.type) ? op : Boolean.FALSE; }
public void setDataType(DataType type) { if (docId != null && docId.hasDocType() && !docId.getDocType().equals(type.getName())) { throw new IllegalArgumentException("Trying to set a document type (" + type.getName() + ") that doesn't match the document id (" + docId + ")."); } super.setDataType(type); setNewType((DocumentType)type); }
getDocumentTypeFromString(documentParseInfo.get().documentId.getDocType(), typeManager), documentParseInfo.get()); operation.setCondition(TestAndSetCondition.fromConditionString(documentParseInfo.get().condition));
/** * Reads a single operation. The operation is not expected to be part of an array. * @param operationType the type of operation (update or put) * @param docIdString document ID. * @return the document */ public DocumentOperation readSingleDocument(DocumentParser.SupportedOperation operationType, String docIdString) { DocumentId docId = new DocumentId(docIdString); final DocumentParseInfo documentParseInfo; try { DocumentParser documentParser = new DocumentParser(parser); documentParseInfo = documentParser.parse(Optional.of(docId)).get(); } catch (IOException e) { state = END_OF_FEED; throw new RuntimeException(e); } documentParseInfo.operationType = operationType; VespaJsonDocumentReader vespaJsonDocumentReader = new VespaJsonDocumentReader(); DocumentOperation operation = vespaJsonDocumentReader.createDocumentOperation( getDocumentTypeFromString(documentParseInfo.documentId.getDocType(), typeManager), documentParseInfo); operation.setCondition(TestAndSetCondition.fromConditionString(documentParseInfo.condition)); return operation; }