net.ravendb.client.documents.operations.configuration.PutClientConfigurationOperation Maven / Gradle / Ivy
package net.ravendb.client.documents.operations.configuration;
import com.fasterxml.jackson.core.JsonProcessingException;
import net.ravendb.client.documents.conventions.DocumentConventions;
import net.ravendb.client.documents.operations.IVoidMaintenanceOperation;
import net.ravendb.client.http.IRaftCommand;
import net.ravendb.client.http.ServerNode;
import net.ravendb.client.http.VoidRavenCommand;
import net.ravendb.client.primitives.ExceptionsUtils;
import net.ravendb.client.primitives.Reference;
import net.ravendb.client.util.RaftIdGenerator;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
public class PutClientConfigurationOperation implements IVoidMaintenanceOperation {
private final ClientConfiguration configuration;
public PutClientConfigurationOperation(ClientConfiguration configuration) {
if (configuration == null) {
throw new IllegalArgumentException("Configuration cannot be null");
}
this.configuration = configuration;
}
@Override
public VoidRavenCommand getCommand(DocumentConventions conventions) {
return new PutClientConfigurationCommand(conventions, this.configuration);
}
private static class PutClientConfigurationCommand extends VoidRavenCommand implements IRaftCommand {
private final String configuration;
public PutClientConfigurationCommand(DocumentConventions conventions, ClientConfiguration configuration) {
if (conventions == null) {
throw new IllegalArgumentException("conventions cannot be null");
}
if (configuration == null) {
throw new IllegalArgumentException("configuration cannot be null");
}
try {
this.configuration = mapper.writeValueAsString(configuration);
} catch (JsonProcessingException e) {
throw ExceptionsUtils.unwrapException(e);
}
}
@Override
public HttpRequestBase createRequest(ServerNode node, Reference url) {
url.value = node.getUrl() + "/databases/" + node.getDatabase() + "/admin/configuration/client";
HttpPut httpPut = new HttpPut();
httpPut.setEntity(new StringEntity(this.configuration, ContentType.APPLICATION_JSON));
return httpPut;
}
@Override
public String getRaftUniqueRequestId() {
return RaftIdGenerator.newId();
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy