View Javadoc
1   /*
2    * Copyright 2020 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.bremersee.data.minio;
18  
19  import io.minio.ObjectWriteResponse;
20  import io.minio.http.Method;
21  import io.minio.messages.DeleteError;
22  import java.time.Duration;
23  import java.util.Collection;
24  import java.util.List;
25  import java.util.Optional;
26  import javax.validation.constraints.NotEmpty;
27  import javax.validation.constraints.NotNull;
28  import org.springframework.lang.Nullable;
29  import org.springframework.validation.annotation.Validated;
30  import org.springframework.web.multipart.MultipartFile;
31  
32  /**
33   * The minio repository interface.
34   *
35   * @author Christian Bremer
36   */
37  @Validated
38  public interface MinioRepository {
39  
40    /**
41     * Gets minio operations.
42     *
43     * @return the minio operations
44     */
45    @NotNull
46    MinioOperations getMinioOperations();
47  
48    /**
49     * Gets region.
50     *
51     * @return the region
52     */
53    String getRegion();
54  
55    /**
56     * Gets bucket.
57     *
58     * @return the bucket
59     */
60    @NotEmpty
61    String getBucket();
62  
63    /**
64     * Is versioning enabled boolean.
65     *
66     * @return the boolean
67     */
68    boolean isVersioningEnabled();
69  
70    /**
71     * Save multipart file.
72     *
73     * @param id the id
74     * @param multipartFile the multipart file
75     * @param deleteMode the delete mode
76     * @return the write response; will be empty, if the multipart file is {@code null} or empty
77     */
78    Optional<ObjectWriteResponse> save(
79        @NotNull MinioObjectId id,
80        @Nullable MultipartFile multipartFile,
81        @NotNull DeleteMode deleteMode);
82  
83    /**
84     * Checks whether an object with the specified name exists or not.
85     *
86     * @param id the id
87     * @return {@code true} if the object exists, otherwise {@code false}
88     */
89    boolean exists(@NotNull MinioObjectId id);
90  
91    /**
92     * Find one.
93     *
94     * @param id the id
95     * @return the multipart file
96     */
97    Optional<MinioMultipartFile> findOne(@NotNull MinioObjectId id);
98  
99    /**
100    * Find all objects.
101    *
102    * @return the list
103    */
104   default List<MinioMultipartFile> findAll() {
105     return findAll(null);
106   }
107 
108   /**
109    * Find all objects.
110    *
111    * @param prefix the prefix
112    * @return the list
113    */
114   List<MinioMultipartFile> findAll(String prefix);
115 
116   /**
117    * Delete.
118    *
119    * @param id the id
120    */
121   void delete(@NotNull MinioObjectId id);
122 
123   /**
124    * Delete all objects.
125    *
126    * @param ids the IDs
127    * @return the list
128    */
129   List<DeleteError> deleteAll(Collection<MinioObjectId> ids);
130 
131   /**
132    * Gets presigned object url.
133    *
134    * @param id the id
135    * @param method the method
136    * @return the presigned object url
137    */
138   default String getPresignedObjectUrl(@NotNull MinioObjectId id, @NotNull Method method) {
139     return getPresignedObjectUrl(id, method, null);
140   }
141 
142   /**
143    * Gets presigned object url.
144    *
145    * @param id the id
146    * @param method the method
147    * @param duration the duration
148    * @return the presigned object url
149    */
150   String getPresignedObjectUrl(
151       @NotNull MinioObjectId id,
152       @NotNull Method method,
153       @Nullable Duration duration);
154 
155 }