|
| 1 | +/* |
| 2 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 3 | + * of this software and associated documentation files (the "Software"), to deal |
| 4 | + * in the Software without restriction, including without limitation the rights |
| 5 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 6 | + * copies of the Software, and to permit persons to whom the Software is |
| 7 | + * furnished to do so, subject to the following conditions: |
| 8 | + * |
| 9 | + * The above copyright notice and this permission notice shall be included in |
| 10 | + * all copies or substantial portions of the Software. |
| 11 | + * |
| 12 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 13 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 14 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 15 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 16 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 17 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 18 | + * THE SOFTWARE. |
| 19 | + */ |
| 20 | +package com.influxdb.client.internal; |
| 21 | + |
| 22 | +import java.time.OffsetDateTime; |
| 23 | +import java.util.logging.Level; |
| 24 | +import java.util.logging.Logger; |
| 25 | +import javax.annotation.Nonnull; |
| 26 | + |
| 27 | +import com.influxdb.Arguments; |
| 28 | +import com.influxdb.client.DeleteApi; |
| 29 | +import com.influxdb.client.domain.DeletePredicateRequest; |
| 30 | +import com.influxdb.client.service.DeleteService; |
| 31 | +import com.influxdb.internal.AbstractRestClient; |
| 32 | + |
| 33 | +import retrofit2.Call; |
| 34 | + |
| 35 | +/** |
| 36 | + * @author Pavlina Rolincova (rolincova@github) (25/10/2019). |
| 37 | + */ |
| 38 | +public class DeleteApiImpl extends AbstractRestClient implements DeleteApi { |
| 39 | + |
| 40 | + private static final Logger LOG = Logger.getLogger(DeleteApiImpl.class.getName()); |
| 41 | + |
| 42 | + private final DeleteService service; |
| 43 | + |
| 44 | + DeleteApiImpl(DeleteService service) { |
| 45 | + |
| 46 | + Arguments.checkNotNull(service, "service"); |
| 47 | + |
| 48 | + this.service = service; |
| 49 | + } |
| 50 | + |
| 51 | + @Override |
| 52 | + public void delete(@Nonnull OffsetDateTime start, |
| 53 | + @Nonnull OffsetDateTime stop, |
| 54 | + @Nonnull String predicate, |
| 55 | + @Nonnull String bucket, |
| 56 | + @Nonnull String organization) { |
| 57 | + |
| 58 | + Arguments.checkNotNull(start, "Start is required"); |
| 59 | + Arguments.checkNotNull(stop, "Stop is required"); |
| 60 | + Arguments.checkNotNull(predicate, "Predicate is required"); |
| 61 | + Arguments.checkNotNull(bucket, "Bucket is required"); |
| 62 | + Arguments.checkNotNull(organization, "Organization is required"); |
| 63 | + |
| 64 | + DeletePredicateRequest request = new DeletePredicateRequest(); |
| 65 | + request.setStart(start); |
| 66 | + request.setStop(stop); |
| 67 | + request.setPredicate(predicate); |
| 68 | + |
| 69 | + delete(request, bucket, organization); |
| 70 | + } |
| 71 | + |
| 72 | + @Override |
| 73 | + public void delete(@Nonnull DeletePredicateRequest predicate, |
| 74 | + @Nonnull String bucket, |
| 75 | + @Nonnull String organization) { |
| 76 | + |
| 77 | + Arguments.checkNotNull(predicate, "Predicate is required"); |
| 78 | + Arguments.checkNotNull(bucket, "Bucket is required"); |
| 79 | + Arguments.checkNotNull(organization, "Organization is required"); |
| 80 | + |
| 81 | + LOG.log(Level.FINEST, |
| 82 | + "Deleting time-series data from InfluxDB (org={0}, bucket={1})...", |
| 83 | + new Object[]{organization, bucket}); |
| 84 | + |
| 85 | + Call<Void> call = service.deletePost(predicate, null, organization, bucket, |
| 86 | + null, null); |
| 87 | + |
| 88 | + execute(call); |
| 89 | + |
| 90 | + LOG.log(Level.FINEST, "Data was deleted from InfluxDB: (org={0}, bucket={1})", |
| 91 | + new Object[]{organization, bucket}); |
| 92 | + } |
| 93 | +} |
0 commit comments