All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.marklogic.client.impl.ResourceServicesImpl Maven / Gradle / Ivy

/*
 * Copyright 2012-2016 MarkLogic Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.marklogic.client.impl;

import com.marklogic.client.admin.ExtensionMetadata;
import com.marklogic.client.Transaction;
import com.marklogic.client.extensions.ResourceServices;
import com.marklogic.client.io.marker.AbstractReadHandle;
import com.marklogic.client.io.marker.AbstractWriteHandle;
import com.marklogic.client.util.RequestLogger;
import com.marklogic.client.util.RequestParameters;

class ResourceServicesImpl
    extends AbstractLoggingManager
    implements ResourceServices
{
	private String       resourceName;
	private RESTServices services;

	ResourceServicesImpl(RESTServices services, String resourceName) {
		super();
		this.services     = services;
		this.resourceName = resourceName;
	}

	@Override
	public String getResourceName() {
		return resourceName;
	}
	private String getResourcePath() {
		return "resources/"+getResourceName();
	}

	@Override
	public  R get(RequestParameters params, R output) {
		return get(params, null, output);
	}
	@Override
	public  R get(RequestParameters params, Transaction transaction, R output) {
		return services.getResource(requestLogger, getResourcePath(), 
				transaction, prepareParams(params), output);
	}
	@Override
	public ServiceResultIterator get(RequestParameters params, String... outputMimetypes) {
		return get(params, null, outputMimetypes);
	}
	@Override
	public ServiceResultIterator get(RequestParameters params, Transaction transaction, String... outputMimetypes) {
		return services.getIteratedResource(requestLogger, getResourcePath(), 
				transaction, prepareParams(params), outputMimetypes);
	}

	@Override
	public  R put(RequestParameters params, AbstractWriteHandle input, R output) {
		return put(params, input, null, output);
	}
	@Override
	public  R put(RequestParameters params, AbstractWriteHandle input, Transaction transaction, R output) {
		return services.putResource(requestLogger, getResourcePath(), 
				transaction, prepareParams(params), input, output);
	}
	@Override
	public  R put(RequestParameters params, W[] input, R output) {
		return put(params, input, null, output);
	}
	@Override
	public  R put(RequestParameters params, W[] input, Transaction transaction, R output) {
		return services.putResource(requestLogger, getResourcePath(),
				transaction, prepareParams(params), input, output);
	}

	@Override
	public  R post(RequestParameters params, AbstractWriteHandle input, R output) {
		return post(params, input, null, output);
	}
	@Override
	public  R post(RequestParameters params, AbstractWriteHandle input, Transaction transaction, R output) {
		return services.postResource(
				requestLogger, getResourcePath(), transaction, prepareParams(params), input, output);
	}
	@Override
	public ServiceResultIterator post(RequestParameters params, AbstractWriteHandle input, String... outputMimetypes) {
		return post(params, input, null, outputMimetypes);
	}
	@Override
	public ServiceResultIterator post(RequestParameters params, AbstractWriteHandle input, Transaction transaction, String... outputMimetypes) {
		return services.postIteratedResource(
				requestLogger, getResourcePath(), transaction, prepareParams(params), input, outputMimetypes);
	}
	@Override
	public  R post(RequestParameters params, W[] input, R output) {
		return post(params, input, null, output);
	}
	@Override
	public  R post(RequestParameters params, W[] input, Transaction transaction, R output) {
		return services.postResource(
				requestLogger, getResourcePath(), transaction, prepareParams(params), input, output);
	}
	@Override
	public  ServiceResultIterator post(RequestParameters params, W[] input, String... outputMimetypes) {
		return post(params, input, null, outputMimetypes);
	}
	@Override
	public  ServiceResultIterator post(RequestParameters params, W[] input, Transaction transaction, String... outputMimetypes) {
		return services.postIteratedResource(
				requestLogger, getResourcePath(), transaction, prepareParams(params), input, outputMimetypes);
	}

	@Override
	public  R delete(RequestParameters params, R output) {
		return delete(params, null, output);
	}
	@Override
	public  R delete(RequestParameters params, Transaction transaction, R output) {
		return services.deleteResource(requestLogger,
				getResourcePath(), transaction, prepareParams(params), output);
	}

	@Override
    public RequestLogger getRequestLogger() {
    	return requestLogger;
    }

	private RequestParameters prepareParams(RequestParameters params) {
		return params != null ? params.copy("rs") : null;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy