private void writeTransform( String transformName, String sourceMimetype, AbstractWriteHandle sourceHandle, ExtensionMetadata metadata) throws ResourceNotFoundException, ResourceNotResendableException, ForbiddenUserException, FailedRequestException { if (transformName == null) throw new IllegalArgumentException("Writing transform with null name"); if (sourceHandle == null) throw new IllegalArgumentException("Writing transform source with null handle"); if (logger.isInfoEnabled()) logger.info("Writing transform source for {}", transformName); HandleImplementation sourceBase = HandleAccessor.checkHandle(sourceHandle, "transform"); Format sourceFormat = sourceBase.getFormat(); if ("application/xquery".equals(sourceMimetype)) { if (Format.TEXT != sourceFormat) sourceBase.setFormat(Format.TEXT); } else if ("application/xslt+xml".equals(sourceMimetype)) { if (Format.XML != sourceFormat) sourceBase.setFormat(Format.XML); } else if ("application/javascript".equals(sourceMimetype)) { if (Format.JSON != sourceFormat) sourceBase.setFormat(Format.JSON); } else { throw new MarkLogicInternalException( "Unsupported mimetype for source: "+sourceMimetype); } if (!sourceMimetype.equals(sourceBase.getMimetype())) sourceBase.setMimetype(sourceMimetype); RequestParameters extraParams = (metadata != null) ? metadata.asParameters() : null; services.putValue(requestLogger, "config/transforms", transformName, extraParams, sourceMimetype, sourceBase); }
@SuppressWarnings("rawtypes") private void checkContentFormat(HandleImplementation contentBase) { if (contentBase == null) return; if (contentFormat != null && contentFormat != Format.UNKNOWN) { Format currFormat = contentBase.getFormat(); if (currFormat != contentFormat) { contentBase.setFormat(contentFormat); if (currFormat != Format.UNKNOWN) contentBase.setMimetype(contentFormat.getDefaultMimetype()); } } }
@SuppressWarnings("rawtypes") private void checkContentFormat(HandleImplementation contentBase) { if (contentBase == null) return; if (contentFormat != null && contentFormat != Format.UNKNOWN) { Format currFormat = contentBase.getFormat(); if (currFormat != contentFormat) { contentBase.setFormat(contentFormat); if (currFormat != Format.UNKNOWN) contentBase.setMimetype(contentFormat.getDefaultMimetype()); } } } protected RequestParameters mergeTransformParameters(ServerTransform transform, RequestParameters extraParams) {
@SuppressWarnings("rawtypes") public DocumentDescriptor create(DocumentUriTemplate template, DocumentMetadataWriteHandle metadataHandle, W contentHandle, ServerTransform transform, Transaction transaction, RequestParameters extraParams) throws ForbiddenUserException, FailedRequestException { if (logger.isInfoEnabled()) logger.info("Creating content"); if (metadataHandle != null) { HandleImplementation metadataBase = HandleAccessor.checkHandle(metadataHandle, "metadata"); Format metadataFormat = metadataBase.getFormat(); if (metadataFormat == null || (metadataFormat != Format.JSON && metadataFormat != Format.XML)) { if (logger.isWarnEnabled()) logger.warn("Unsupported metadata format {}, using XML",metadataFormat.name()); metadataBase.setFormat(Format.XML); } } checkContentFormat(contentHandle); return services.postDocument( requestLogger, template, (transaction == null) ? null : transaction.getTransactionId(), (metadataHandle != null) ? processedMetadata : null, mergeTransformParameters( (transform != null) ? transform : getWriteTransform(), extraParams ), metadataHandle, contentHandle ); }
private void copyDescriptor(DocumentDescriptor desc, HandleImplementation handleBase) { if (handleBase == null) return; handleBase.setFormat(desc.getFormat()); handleBase.setMimetype(desc.getMimetype()); handleBase.setByteLength(desc.getByteLength()); }
@SuppressWarnings("rawtypes") public void write(DocumentDescriptor desc, DocumentMetadataWriteHandle metadataHandle, W contentHandle, ServerTransform transform, Transaction transaction, RequestParameters extraParams) throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException { if (desc == null) throw new IllegalArgumentException("Writing document with null identifier"); if (logger.isInfoEnabled()) logger.info("Writing content for {}",desc.getUri()); if (metadataHandle != null) { HandleImplementation metadataBase = HandleAccessor.checkHandle(metadataHandle, "metadata"); Format metadataFormat = metadataBase.getFormat(); if (metadataFormat == null || (metadataFormat != Format.JSON && metadataFormat != Format.XML)) { if (logger.isWarnEnabled()) logger.warn("Unsupported metadata format {}, using XML",metadataFormat.name()); metadataBase.setFormat(Format.XML); } } checkContentFormat(contentHandle); services.putDocument( requestLogger, desc, (transaction == null) ? null : transaction.getTransactionId(), (metadataHandle != null) ? processedMetadata : null, mergeTransformParameters( (transform != null) ? transform : getWriteTransform(), extraParams ), metadataHandle, contentHandle ); }
if (logger.isWarnEnabled()) logger.warn("Unsupported metadata format {}, using XML",metadataFormat.name()); metadataBase.setFormat(Format.XML);
logger.warn("Unsupported metadata format {}, using XML", metadataFormat.name()); metadataBase.setFormat(Format.XML);
@SuppressWarnings("rawtypes") protected DocumentDescriptorImpl create(DocumentUriTemplate template, DocumentMetadataWriteHandle metadataHandle, W contentHandle, ServerTransform transform, Transaction transaction, String temporalCollection, Calendar systemTime, RequestParameters extraParams) { if ( logger.isInfoEnabled() ) logger.info("Creating content"); if ( extraParams == null ) extraParams = getWriteParams(); if (metadataHandle != null) { HandleImplementation metadataBase = HandleAccessor.checkHandle( metadataHandle, "metadata"); Format metadataFormat = metadataBase.getFormat(); if (metadataFormat == null || (metadataFormat != Format.JSON && metadataFormat != Format.XML)) { if (logger.isWarnEnabled()) logger.warn("Unsupported metadata format {}, using XML", metadataFormat.name()); metadataBase.setFormat(Format.XML); } } extraParams = addTemporalParams(extraParams, temporalCollection, null, systemTime); checkContentFormat(contentHandle); return services.postDocument( requestLogger, template, transaction, (metadataHandle != null) ? processedMetadata : null, mergeTransformParameters((transform != null) ? transform : getWriteTransform(), extraParams), metadataHandle, contentHandle); }
logger.warn("Unsupported metadata format {}, using XML", metadataFormat.name()); metadataBase.setFormat(Format.XML);
private void copyDescriptor(DocumentDescriptor desc, HandleImplementation handleBase) { if (handleBase == null) return; if (desc.getFormat() != null) handleBase.setFormat(desc.getFormat()); if (desc.getMimetype() != null) handleBase.setMimetype(desc.getMimetype()); handleBase.setByteLength(desc.getByteLength()); }
private HandleImplementation executeSetRdfXmlOrJsonMimetype(Format format, String mimeType) { HandleImplementation triplesHandle = new HandleImplementationTester(); triplesHandle.setFormat(format); triplesHandle.setMimetype(mimeType); RESTServices services = mock(RESTServices.class); SPARQLQueryManagerImpl sparqlQueryManager = new SPARQLQueryManagerImpl(services); SPARQLQueryDefinition qdef = new SPARQLQueryDefinitionImpl(); sparqlQueryManager.executeDescribe(qdef, (TriplesReadHandle) triplesHandle); return triplesHandle; }
@SuppressWarnings("unchecked") public <T extends StructureReadHandle> T convertOrValidate(RawQueryByExampleDefinition query, T convertedHandle, String view) { RequestParameters params = new RequestParameters(); params.add("view", view); @SuppressWarnings("rawtypes") HandleImplementation convertedBase = HandleAccessor.checkHandle(convertedHandle, "convert"); Format convertedFormat = convertedBase.getFormat(); if(convertedFormat == Format.UNKNOWN ) { @SuppressWarnings("rawtypes") HandleImplementation queryBase = HandleAccessor.checkHandle(query.getHandle(), "validate"); if (queryBase.getFormat() == Format.UNKNOWN) { convertedBase.setFormat(Format.XML); } } String optionsName = query.getOptionsName(); if (optionsName != null && optionsName.length() > 0) { params.add("options", optionsName); } services.postResource(requestLogger, "qbe", null, params, query.getHandle(), convertedHandle); return convertedHandle; }