/*- * ============LICENSE_START======================================================= * 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. * ============LICENSE_END========================================================= */ package com.woorea.openstack.swift.api; import java.util.Map; import com.woorea.openstack.base.client.OpenStackClient; import com.woorea.openstack.base.client.OpenStackRequest; import com.woorea.openstack.base.client.OpenStackResponse; import com.woorea.openstack.swift.model.ObjectDownload; import com.woorea.openstack.swift.model.ObjectForUpload; public class ContainerResource { private final OpenStackClient CLIENT; private String container; public ContainerResource(OpenStackClient client, String container) { CLIENT = client; this.container = container; } public List list() { return new List(container, null); } public CreateDirectory createDirectory(String path) { return new CreateDirectory(container, path); } public Show show(String path) { return new Show(container, path); } public Upload upload(ObjectForUpload objectForUpload) { return new Upload(objectForUpload); } public Download download(String path) { return new Download(container, path); } public Delete delete(String path) { return new Delete(container, path); } public class List extends OpenStackRequest> { private String containerName; private Map filters; public List(String containerName, Map filters) { this.containerName = containerName; this.filters = filters; //returnType(new TypeToken>(){}); // target = target.path(containerName); // for(String filter : new String[]{"prefix","delimiter","path","marker"}) { // if(filters.get(filter) != null) { // target = target.queryParam(filter, filters.get(filter)); // } // } // return target.request(MediaType.APPLICATION_JSON).get(new GenericType>(){}); } } public class CreateDirectory extends OpenStackRequest { private String container; private String path; public CreateDirectory(String container, String path) { this.container = container; this.path = path; // endpoint.path(container).path(path).request().put(Entity.entity(new byte[1],"application/directory")); } } public class Show extends OpenStackRequest { private String containerName; private String objectName; public Show(String containerName, String objectName) { this.containerName = containerName; this.objectName = objectName; // return target.path(containerName).path(objectName).request(MediaType.APPLICATION_JSON).head(); } } public class Upload extends OpenStackRequest { private ObjectForUpload objectForUpload; public Upload(ObjectForUpload objectForUpload) { this.objectForUpload = objectForUpload; // Invocation.Builder invocationBuilder = target.path(objectForUpload.getContainer()).path(objectForUpload.getName()).request(MediaType.APPLICATION_JSON); // for(String key : objectForUpload.getProperties().keySet()) { // invocationBuilder.header("x-object-meta-" + key, objectForUpload.getProperties().get(key)); // } // return invocationBuilder.put(Entity.entity(objectForUpload.getInputStream(), MediaType.APPLICATION_OCTET_STREAM), Response.class); } } public class Download extends OpenStackRequest { private String containerName; private String objectName; public Download(String containerName, String objectName) { this.containerName = containerName; this.objectName = objectName; // Response response = target.path(containerName).path(objectName).request(MediaType.APPLICATION_JSON).get(); // ObjectDownload objectDownload = new ObjectDownload(); // objectDownload.setInputStream((InputStream) response.getEntity()); // return objectDownload; } } public class Delete extends OpenStackRequest { private String containerName; private String objectName; public Delete(String containerName, String objectName) { this.containerName = containerName; this.objectName = objectName; //return target.path(containerName).path(objectName).request(MediaType.APPLICATION_JSON).delete(); } } }