Skip to content

Commit

Permalink
Add argument to calculate md5 if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
sinhaashish committed Feb 6, 2020
1 parent 60dfc03 commit 1462c63
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 91 deletions.
3 changes: 0 additions & 3 deletions api/src/main/java/io/minio/DateFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,5 @@ public class DateFormat {
public static final DateTimeFormatter HTTP_HEADER_DATE_FORMAT =
DateTimeFormat.forPattern("EEE',' dd MMM yyyy HH':'mm':'ss 'GMT'").withZoneUTC().withLocale(Locale.US);

public static final DateTimeFormatter RETENTION_DATE_FORMAT = EXPIRATION_DATE_FORMAT;
// DateTimeFormat.forPattern("yyyy-MM-dd'T'HH':'mm':'ss'Z'").withZoneUTC().withLocale(Locale.US);

private DateFormat() {}
}
150 changes: 105 additions & 45 deletions api/src/main/java/io/minio/MinioClient.java

Large diffs are not rendered by default.

18 changes: 10 additions & 8 deletions api/src/main/java/io/minio/messages/ObjectLockLegalHold.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,19 @@ public class ObjectLockLegalHold extends XmlEntity{
private String status;

/**
* Constructs a new CustomRetention object with given retention.
* Constructs a new ObjectLockLegalHold object .
*/
public ObjectLockLegalHold() throws XmlPullParserException {
super();
super.name = "LegalHold";
}

/**
* Constructs a new CustomRetention object with given retention.
* Constructs a new ObjectLockLegalHold object with given status.
*/
public ObjectLockLegalHold(boolean legalHold) throws XmlPullParserException {
super();
super.name = "LegalHold";
if (legalHold) {
public ObjectLockLegalHold(boolean status) throws XmlPullParserException {
this();
if (status) {
this.status = "ON";
} else {
this.status = "OFF";
Expand All @@ -52,7 +51,10 @@ public ObjectLockLegalHold(boolean legalHold) throws XmlPullParserException {
/**
* Indicates whether the specified object has a Legal Hold in place or not.
*/
public Boolean getStatus() {
return Boolean.parseBoolean(status);
public boolean status() {
if (status.equals("ON")) {
return true;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.xmlpull.v1.XmlPullParserException;

import io.minio.DateFormat;
import java.util.Date;
import org.joda.time.DateTime;
import com.google.api.client.util.Key;
import io.minio.errors.InvalidArgumentException;
Expand All @@ -35,29 +34,28 @@ public class ObjectRetentionConfiguration extends XmlEntity {
private String retainUntilDate;

/**
* Constructs a new ObjectLockRetention object.
* Constructs a new ObjectRetentionConfiguration object.
*/
public ObjectRetentionConfiguration() throws XmlPullParserException {
super();
super.name = "Retention";
}

/**
* Constructs a new CustomRetention object with given retention.
* Constructs a new ObjectRetentionConfiguration object with given retention
* until date and mode.
*/
public ObjectRetentionConfiguration(RetentionMode mode, DateTime retainUntilDate) throws XmlPullParserException,
InvalidArgumentException {
super();
super.name = "Retention";
this();
if (mode == null) {
throw new InvalidArgumentException("null is not allowed in mode. Valid values are 'COMPLIANCE' and 'GOVERNANCE'");
throw new InvalidArgumentException("null mode is not allowed");
}
this.mode = mode.toString();
if (retainUntilDate == null) {
throw new InvalidArgumentException("retain until date cant be null, it must be a valid date.");
}

this.retainUntilDate = retainUntilDate.toString(DateFormat.RETENTION_DATE_FORMAT);
throw new InvalidArgumentException("null retainUntilDate is not allowed");
}
this.retainUntilDate = retainUntilDate.toString(DateFormat.EXPIRATION_DATE_FORMAT);
}

/**
Expand All @@ -70,11 +68,11 @@ public RetentionMode mode() {
/**
* Returns retain until date.
*/
public Date retainUntil() {
public DateTime retainUntilDate() {
if (retainUntilDate == null ) {
return null;
}
return DateFormat.RETENTION_DATE_FORMAT.parseDateTime(retainUntilDate).toDate();
return DateFormat.EXPIRATION_DATE_FORMAT.parseDateTime(retainUntilDate);
}
}

28 changes: 19 additions & 9 deletions examples/EnableDisableObjectLegalHold.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,36 @@
* limitations under the License.
*/

import io.minio.MinioClient;
import io.minio.errors.ErrorResponseException;
import io.minio.errors.InsufficientDataException;
import io.minio.errors.InternalException;
import io.minio.errors.InvalidBucketNameException;
import io.minio.errors.InvalidEndpointException;
import io.minio.errors.InvalidResponseException;
import io.minio.errors.InvalidPortException;
import io.minio.errors.InvalidArgumentException;
import io.minio.errors.MinioException;
import io.minio.errors.NoResponseException;
import io.minio.errors.RegionConflictException;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;

import java.security.InvalidKeyException;
import java.lang.StringBuilder;
import java.io.ByteArrayInputStream;

import java.security.NoSuchAlgorithmException;
import org.xmlpull.v1.XmlPullParserException;

import io.minio.MinioClient;
import io.minio.errors.MinioException;

public class EnableDisableObjectLegalHold {
/**
* MinioClient.enableObjectLegalHold() example.
* MinioClient.disableObjectLegalHold() example.
* MinioClient.isObjectLegalHoldEnabled() example.
*/
public static void main(String[] args)
throws IOException, NoSuchAlgorithmException, InvalidKeyException, XmlPullParserException {
throws IOException, NoSuchAlgorithmException, InvalidKeyException, XmlPullParserException,
InvalidResponseException, InsufficientDataException, NoResponseException,
InternalException, ErrorResponseException, InvalidBucketNameException,
InvalidPortException, InvalidEndpointException, RegionConflictException,
InvalidArgumentException {
try {

/* play.min.io for test and development. */
Expand Down
42 changes: 28 additions & 14 deletions examples/SetGetObjectLockRetentionConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,41 @@
* limitations under the License.
*/

import io.minio.MinioClient;
import io.minio.errors.ErrorResponseException;
import io.minio.errors.InsufficientDataException;
import io.minio.errors.InternalException;
import io.minio.errors.InvalidBucketNameException;
import io.minio.errors.InvalidEndpointException;
import io.minio.errors.InvalidResponseException;
import io.minio.errors.InvalidPortException;
import io.minio.errors.InvalidArgumentException;
import io.minio.errors.MinioException;
import io.minio.errors.NoResponseException;
import io.minio.errors.RegionConflictException;
import io.minio.messages.ObjectRetentionConfiguration;
import io.minio.messages.RetentionMode;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Calendar;

import org.joda.time.DateTime;
import java.security.InvalidKeyException;
import java.lang.StringBuilder;
import java.io.ByteArrayInputStream;

import org.xmlpull.v1.XmlPullParserException;

import io.minio.MinioClient;
import io.minio.messages.ObjectRetentionConfiguration;
import io.minio.messages.RetentionMode;
import io.minio.errors.MinioException;

public class SetGetObjectLockRetentionConfig {
/**
* MinioClient.setObjectRetention() example.
* MinioClient.getObjectRetention() example.
*/
public static void main(String[] args)
throws IOException, NoSuchAlgorithmException, InvalidKeyException, XmlPullParserException {
throws IOException, NoSuchAlgorithmException, InvalidKeyException, XmlPullParserException,
InvalidResponseException, InsufficientDataException, NoResponseException,
InternalException, ErrorResponseException, InvalidBucketNameException,
InvalidPortException, InvalidEndpointException, RegionConflictException,
InvalidArgumentException {
try {

/* play.min.io for test and development. */
Expand All @@ -53,10 +65,9 @@ public static void main(String[] args)
System.out.println("my-bucketname is created successfully with object lock functionality enabled.");
}

DateTime retentionUntil = new DateTime(2025, Calendar.MAY, 0, 0, 0);

StringBuilder builder = new StringBuilder();
for (int i = 0; i < 1000; i++) {
for (int i = 0; i < 100; i++) {
builder.append("Sphinx of black quartz, judge my vow: Used by Adobe InDesign to display font samples. ");
builder.append("(29 letters)\n");
builder.append("Jackdaws love my big sphinx of quartz: Similarly, used by Windows XP for some fonts. ");
Expand All @@ -73,7 +84,10 @@ public static void main(String[] args)
System.out.println("my-objectname is uploaded successfully");

// Declaring config with Retention mode as Compliance and
// retain until MAY 2025
// retain until MAY 2021


DateTime retentionUntil = new DateTime(2021, Calendar.MAY, 0, 0, 0);
ObjectRetentionConfiguration config =
new ObjectRetentionConfiguration(RetentionMode.COMPLIANCE, retentionUntil);

Expand All @@ -85,7 +99,7 @@ public static void main(String[] args)
"my-objectname", "" );

System.out.println(" Mode : " + objectRetentionConfiguration.mode());
//System.out.println(" Retainuntil Date : " + objectRetentionConfiguration.getRetentionDate());
System.out.println(" Retainuntil Date : " + objectRetentionConfiguration.retainUntilDate());

} catch (MinioException e) {
System.out.println("Error occurred: " + e);
Expand Down

0 comments on commit 1462c63

Please sign in to comment.