List of usage examples for org.joda.time DateTime toString
public String toString(String pattern)
From source file:io.konig.data.app.common.ExtentContainer.java
License:Apache License
public boolean validateQueryParam(String key, String value, URI datatype) throws DataAppException { try {/*from w ww. ja va 2 s . co m*/ if (XMLSchema.DATE.equals(datatype)) { DateTime localTime = new DateTime(value).toDateTime(DateTimeZone.UTC); localTime.toString(ISODateTimeFormat.date()); return true; } else if (XMLSchema.STRING.equals(datatype)) { if (VIEW.equals(key) && FusionCharts.MAP_MEDIA_TYPE.equals(value)) { return true; } else if (VIEW.equals(key) && FusionCharts.MSLINE_MEDIA_TYPE.equals(value)) { return true; } else if (VIEW.equals(key) && FusionCharts.BAR_MEDIA_TYPE.equals(value)) { return true; } else if (VIEW.equals(key) && FusionCharts.PIE_MEDIA_TYPE.equals(value)) { return true; } else if (AGGREGATE.equals(key)) { AggregateAs.valueOf(value); return true; } else if (XSORT.equals(key) || YSORT.equals(key)) { SortAs.valueOf(value); return true; } } else if (XMLSchema.LONG.equals(datatype)) { Long.parseLong(value); return true; } throw new DataAppException("Invalid Input", 400); } catch (Exception ex) { throw new DataAppException("Invalid Input", 400); } }
From source file:io.minio.CopyConditions.java
License:Apache License
/** * Set modified condition, copy object modified since given time. * * @throws InvalidArgumentException//from w w w .j a v a 2 s . co m * When date is null */ public void setModified(DateTime date) throws InvalidArgumentException { if (date == null) { throw new InvalidArgumentException("Date cannot be empty"); } copyConditions.put("x-amz-copy-source-if-modified-since", date.toString(DateFormat.HTTP_HEADER_DATE_FORMAT)); }
From source file:io.minio.CopyConditions.java
License:Apache License
/** * Sets object unmodified condition, copy object unmodified since given time. * * @throws InvalidArgumentException/*from www . ja va 2 s. c om*/ * When date is null */ public void setUnmodified(DateTime date) throws InvalidArgumentException { if (date == null) { throw new InvalidArgumentException("Date can not be null"); } copyConditions.put("x-amz-copy-source-if-unmodified-since", date.toString(DateFormat.HTTP_HEADER_DATE_FORMAT)); }
From source file:io.minio.MinioClient.java
License:Apache License
/** * Creates Request object for given request parameters. * * @param method HTTP method./* ww w .ja v a 2 s . c o m*/ * @param bucketName Bucket name. * @param objectName Object name in the bucket. * @param region Amazon S3 region of the bucket. * @param headerMap Map of HTTP headers for the request. * @param queryParamMap Map of HTTP query parameters of the request. * @param contentType Content type of the request body. * @param body HTTP request body. * @param length Length of HTTP request body. */ private Request createRequest(Method method, String bucketName, String objectName, String region, Map<String, String> headerMap, Map<String, String> queryParamMap, final String contentType, final Object body, final int length) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException { if (bucketName == null && objectName != null) { throw new InvalidBucketNameException(NULL_STRING, "null bucket name for object '" + objectName + "'"); } HttpUrl.Builder urlBuilder = this.baseUrl.newBuilder(); if (bucketName != null) { checkBucketName(bucketName); String host = this.baseUrl.host(); if (host.equals(S3_AMAZONAWS_COM)) { // special case: handle s3.amazonaws.com separately if (region != null) { host = AwsS3Endpoints.INSTANCE.endpoint(region); } boolean usePathStyle = false; if (method == Method.PUT && objectName == null && queryParamMap == null) { // use path style for make bucket to workaround "AuthorizationHeaderMalformed" error from s3.amazonaws.com usePathStyle = true; } else if (queryParamMap != null && queryParamMap.containsKey("location")) { // use path style for location query usePathStyle = true; } else if (bucketName.contains(".") && this.baseUrl.isHttps()) { // use path style where '.' in bucketName causes SSL certificate validation error usePathStyle = true; } if (usePathStyle) { urlBuilder.host(host); urlBuilder.addPathSegment(bucketName); } else { urlBuilder.host(bucketName + "." + host); } } else { urlBuilder.addPathSegment(bucketName); } } if (objectName != null) { for (String pathSegment : objectName.split("/")) { // Limitation: // 1. OkHttp does not allow to add '.' and '..' as path segment. // 2. Its not allowed to add path segment as '/', '//', '/usr' or 'usr/'. urlBuilder.addPathSegment(pathSegment); } } if (queryParamMap != null) { for (Map.Entry<String, String> entry : queryParamMap.entrySet()) { urlBuilder.addEncodedQueryParameter(Signer.encodeQueryString(entry.getKey()), Signer.encodeQueryString(entry.getValue())); } } RequestBody requestBody = null; if (body != null) { requestBody = new RequestBody() { @Override public MediaType contentType() { if (contentType != null) { return MediaType.parse(contentType); } else { return MediaType.parse("application/octet-stream"); } } @Override public long contentLength() { if (body instanceof InputStream || body instanceof RandomAccessFile || body instanceof byte[]) { return length; } if (length == 0) { return -1; } else { return length; } } @Override public void writeTo(BufferedSink sink) throws IOException { byte[] data = null; if (body instanceof InputStream) { InputStream stream = (InputStream) body; sink.write(Okio.source(stream), length); } else if (body instanceof RandomAccessFile) { RandomAccessFile file = (RandomAccessFile) body; sink.write(Okio.source(Channels.newInputStream(file.getChannel())), length); } else if (body instanceof byte[]) { sink.write(data, 0, length); } else { sink.writeUtf8(body.toString()); } } }; } HttpUrl url = urlBuilder.build(); // urlBuilder does not encode some characters properly for Amazon S3. // Encode such characters properly here. List<String> pathSegments = url.encodedPathSegments(); urlBuilder = url.newBuilder(); for (int i = 0; i < pathSegments.size(); i++) { urlBuilder.setEncodedPathSegment(i, pathSegments.get(i).replaceAll("\\!", "%21").replaceAll("\\$", "%24").replaceAll("\\&", "%26") .replaceAll("\\'", "%27").replaceAll("\\(", "%28").replaceAll("\\)", "%29") .replaceAll("\\*", "%2A").replaceAll("\\+", "%2B").replaceAll("\\,", "%2C") .replaceAll("\\:", "%3A").replaceAll("\\;", "%3B").replaceAll("\\=", "%3D") .replaceAll("\\@", "%40").replaceAll("\\[", "%5B").replaceAll("\\]", "%5D")); } url = urlBuilder.build(); Request.Builder requestBuilder = new Request.Builder(); requestBuilder.url(url); requestBuilder.method(method.toString(), requestBody); if (headerMap != null) { for (Map.Entry<String, String> entry : headerMap.entrySet()) { requestBuilder.header(entry.getKey(), entry.getValue()); } } String sha256Hash = null; String md5Hash = null; if (this.accessKey != null && this.secretKey != null) { // No need to compute sha256 if endpoint scheme is HTTPS. Issue #415. if (url.isHttps()) { sha256Hash = "UNSIGNED-PAYLOAD"; if (body instanceof BufferedInputStream) { md5Hash = Digest.md5Hash((BufferedInputStream) body, length); } else if (body instanceof RandomAccessFile) { md5Hash = Digest.md5Hash((RandomAccessFile) body, length); } else if (body instanceof byte[]) { byte[] data = (byte[]) body; md5Hash = Digest.md5Hash(data, length); } } else { if (body == null) { sha256Hash = Digest.sha256Hash(new byte[0]); } else { if (body instanceof BufferedInputStream) { String[] hashes = Digest.sha256md5Hashes((BufferedInputStream) body, length); sha256Hash = hashes[0]; md5Hash = hashes[1]; } else if (body instanceof RandomAccessFile) { String[] hashes = Digest.sha256md5Hashes((RandomAccessFile) body, length); sha256Hash = hashes[0]; md5Hash = hashes[1]; } else if (body instanceof byte[]) { byte[] data = (byte[]) body; sha256Hash = Digest.sha256Hash(data, length); md5Hash = Digest.md5Hash(data, length); } else { sha256Hash = Digest.sha256Hash(body.toString()); } } } } if (md5Hash != null) { requestBuilder.header("Content-MD5", md5Hash); } if (url.port() == 80 || url.port() == 443) { requestBuilder.header("Host", url.host()); } else { requestBuilder.header("Host", url.host() + ":" + url.port()); } requestBuilder.header("User-Agent", this.userAgent); if (sha256Hash != null) { requestBuilder.header("x-amz-content-sha256", sha256Hash); } DateTime date = new DateTime(); requestBuilder.header("x-amz-date", date.toString(DateFormat.AMZ_DATE_FORMAT)); return requestBuilder.build(); }
From source file:io.minio.PostPolicy.java
License:Apache License
/** * Returns form data of this post policy. *///from www .j a v a 2s .c o m public Map<String, String> formData(String accessKey, String secretKey) throws NoSuchAlgorithmException, InvalidKeyException { ArrayList<String[]> conditions = new ArrayList<>(); Map<String, String> formData = new HashMap<>(); conditions.add(new String[] { "eq", "$bucket", this.bucketName }); formData.put("bucket", this.bucketName); if (this.startsWith) { conditions.add(new String[] { "starts-with", "$key", this.objectName }); formData.put("key", this.objectName); } else { conditions.add(new String[] { "eq", "$key", this.objectName }); formData.put("key", this.objectName); } if (this.contentType != null) { conditions.add(new String[] { "eq", "$Content-Type", this.contentType }); formData.put("Content-Type", this.contentType); } if (this.contentRangeStart > 0 && this.contentRangeEnd > 0) { conditions.add(new String[] { "content-length-range", Long.toString(this.contentRangeStart), Long.toString(this.contentRangeEnd) }); } conditions.add(new String[] { "eq", "$x-amz-algorithm", ALGORITHM }); formData.put("x-amz-algorithm", ALGORITHM); DateTime date = new DateTime(); String region = BucketRegionCache.INSTANCE.region(this.bucketName); String credential = Signer.credential(accessKey, date, region); conditions.add(new String[] { "eq", "$x-amz-credential", credential }); formData.put("x-amz-credential", credential); String amzDate = date.toString(DateFormat.AMZ_DATE_FORMAT); conditions.add(new String[] { "eq", "$x-amz-date", amzDate }); formData.put("x-amz-date", amzDate); String policybase64 = BaseEncoding.base64().encode(this.marshalJson(conditions)); String signature = Signer.postPresignV4(policybase64, secretKey, date, region); formData.put("policy", policybase64); formData.put("x-amz-signature", signature); return formData; }
From source file:io.minio.RequestSigner.java
License:Apache License
private static byte[] getSigningKey(DateTime date, String region, String secretKey) throws NoSuchAlgorithmException, InvalidKeyException, UnsupportedEncodingException { String formattedDate = date.toString(dateFormatyyyyMMdd); String dateKeyLine = "AWS4" + secretKey; byte[] dateKey = sumHmac(dateKeyLine.getBytes("UTF-8"), formattedDate.getBytes("UTF-8")); byte[] dateRegionKey = sumHmac(dateKey, region.getBytes("UTF-8")); byte[] dateRegionServiceKey = sumHmac(dateRegionKey, "s3".getBytes("UTF-8")); return sumHmac(dateRegionServiceKey, "aws4_request".getBytes("UTF-8")); }
From source file:io.minio.RequestSigner.java
License:Apache License
private String getScope(String region, DateTime date) { String formattedDate = date.toString(dateFormatyyyyMMdd); return formattedDate + "/" + region + "/" + "s3" + "/" + "aws4_request"; }
From source file:io.minio.RequestSigner.java
License:Apache License
private String getStringToSign(String region, String canonicalHash, DateTime date) { return "AWS4-HMAC-SHA256" + "\n" + date.toString(dateFormatyyyyMMddThhmmssZ) + "\n" + getScope(region, date) + "\n" + canonicalHash; }
From source file:io.minio.Signer.java
License:Apache License
/** * Returns credential string of given access key, date and region. */// w ww .j a va 2 s. c o m public static String credential(String accessKey, DateTime date, String region) { return accessKey + "/" + date.toString(DateFormat.SIGNER_DATE_FORMAT) + "/" + region + "/s3/aws4_request"; }
From source file:io.terminus.snz.user.service.SupplierInfoChangedServiceImpl.java
@Override public SupplierInfoChangedDto baseCompanyChanged(Long userId, CompanyDto updatedCompanyDto, Company oldCompany, List<CompanyMainBusiness> oldMainBusinesses, List<CompanySupplyPark> oldSupplyParks) { SupplierInfoChangedDto supplierInfoChangedDto = new SupplierInfoChangedDto(); Company updatedCompany = updatedCompanyDto.getCompany(); List<CompanyMainBusiness> updatedMainBusinesses = updatedCompanyDto.getCompanyMainBusinesses(); List<CompanySupplyPark> updatedSupplyParks = updatedCompanyDto.getCompanySupplyParks(); //??//from w w w . ja v a 2 s .c o m CompanyDto newCompanyDto = getNewBaseCompany(userId, oldCompany, oldMainBusinesses, oldSupplyParks) .getSupplierInfo(); Company newCompany = newCompanyDto.getCompany(); List<CompanyMainBusiness> newMainBusinesses = newCompanyDto.getCompanyMainBusinesses(); List<CompanySupplyPark> newSupplyParks = newCompanyDto.getCompanySupplyParks(); Map<String, String> changedInfo = Maps.newHashMap(); if (!Objects.equal(updatedCompany.getCorporation(), newCompany.getCorporation())) { changedInfo.put(ChangedInfoKeys.companyCorporation(), updatedCompany.getCorporation()); updatedCompany.setCorporation(null); } if (!Objects.equal(updatedCompany.getInitAgent(), newCompany.getInitAgent())) { changedInfo.put(ChangedInfoKeys.companyInitAgent(), updatedCompany.getInitAgent()); updatedCompany.setInitAgent(null); } if (!Objects.equal(updatedCompany.getDesc(), newCompany.getDesc())) { changedInfo.put(ChangedInfoKeys.companyDesc(), updatedCompany.getDesc()); updatedCompany.setDesc(null); } if (!Objects.equal(updatedCompany.getRegCountry(), newCompany.getRegCountry())) { changedInfo.put(ChangedInfoKeys.companyRegCountry(), String.valueOf(updatedCompany.getRegCountry())); updatedCompany.setRegCountry(null); } // if (!Objects.equal(company.getCustomers(), newCompany.getCustomers())) { // changedInfo.put("", newCompany.getCustomers()); // } // if (!Objects.equal(updatedCompany.getProductLine(), newCompany.getProductLine())) { changedInfo.put(ChangedInfoKeys.companyProductLine(), updatedCompany.getProductLine()); } if (mainBusinessChanged(updatedMainBusinesses, newMainBusinesses)) { changedInfo.put(ChangedInfoKeys.companyMainBusiness(), JsonMapper.nonEmptyMapper().toJson(updatedMainBusinesses)); } if (supplyParkChanged(updatedSupplyParks, newSupplyParks)) { changedInfo.put(ChangedInfoKeys.companySupplyPark(), JsonMapper.nonEmptyMapper().toJson(updatedSupplyParks)); } //V???? if (!Strings.isNullOrEmpty(newCompany.getSupplierCode())) { if (!Objects.equal(updatedCompany.getGroupName(), newCompany.getGroupName())) { changedInfo.put(ChangedInfoKeys.companyGroupName(), updatedCompany.getGroupName()); updatedCompany.setGroupName(null); } if (!Objects.equal(updatedCompany.getGroupAddr(), newCompany.getGroupAddr())) { changedInfo.put(ChangedInfoKeys.companyGroupAddr(), updatedCompany.getGroupAddr()); updatedCompany.setGroupAddr(null); } if (!Objects.equal(updatedCompany.getRegCapital(), newCompany.getRegCapital())) { changedInfo.put(ChangedInfoKeys.companyRegCapical(), String.valueOf(updatedCompany.getRegCapital())); updatedCompany.setRegCapital(null); } if (!Objects.equal(updatedCompany.getRcCoinType(), newCompany.getRcCoinType())) { changedInfo.put(ChangedInfoKeys.companyRcCoinType(), String.valueOf(updatedCompany.getRcCoinType())); updatedCompany.setRcCoinType(null); } if (!Objects.equal(updatedCompany.getPersonScale(), newCompany.getPersonScale())) { changedInfo.put(ChangedInfoKeys.companyPersonScale(), updatedCompany.getPersonScale()); updatedCompany.setPersonScale(null); } if (!Objects.equal(updatedCompany.getRegProvince(), newCompany.getRegProvince())) { changedInfo.put(ChangedInfoKeys.companyRegProvince(), String.valueOf(updatedCompany.getRegProvince())); updatedCompany.setRegProvince(null); } if (!Objects.equal(updatedCompany.getRegCity(), newCompany.getRegCity())) { changedInfo.put(ChangedInfoKeys.companyRegCity(), String.valueOf(updatedCompany.getRegCity())); updatedCompany.setRegCity(null); } if (!Objects.equal(updatedCompany.getFixedAssets(), newCompany.getFixedAssets())) { changedInfo.put(ChangedInfoKeys.companyFixedAssets(), String.valueOf(updatedCompany.getFixedAssets())); updatedCompany.setFixedAssets(null); } if (!Objects.equal(updatedCompany.getFaCoinType(), newCompany.getFaCoinType())) { changedInfo.put(ChangedInfoKeys.companyFaCoinType(), String.valueOf(updatedCompany.getFaCoinType())); updatedCompany.setFaCoinType(null); } Date updatedFoundAt = updatedCompany.getFoundAt(); Date oldFoundAt = newCompany.getFoundAt(); if (updatedFoundAt != null) { DateTime updated = new DateTime(updatedFoundAt); if (oldFoundAt == null) { changedInfo.put(ChangedInfoKeys.companyFoundAt(), updated.toString(FORMATTER)); updatedCompany.setFoundAt(null); } else { DateTime old = new DateTime(oldFoundAt); if (!updated.equals(old)) { changedInfo.put(ChangedInfoKeys.companyFoundAt(), updated.toString(FORMATTER)); updatedCompany.setFoundAt(null); } } } if (!Objects.equal(updatedCompany.getOfficialWebsite(), newCompany.getOfficialWebsite())) { changedInfo.put(ChangedInfoKeys.companyOfficialWebSite(), updatedCompany.getOfficialWebsite()); updatedCompany.setOfficialWebsite(null); } if (!Objects.equal(updatedCompany.getNature(), newCompany.getNature())) { changedInfo.put(ChangedInfoKeys.companyNature(), String.valueOf(updatedCompany.getNature())); updatedCompany.setNature(null); } if (!Objects.equal(updatedCompany.getWorldTop(), newCompany.getWorldTop())) { changedInfo.put(ChangedInfoKeys.companyWorldTop(), String.valueOf(updatedCompany.getWorldTop())); updatedCompany.setWorldTop(null); } if (!Objects.equal(updatedCompany.getListedStatus(), newCompany.getListedStatus())) { changedInfo.put(ChangedInfoKeys.companyListedStatus(), String.valueOf(updatedCompany.getListedStatus())); updatedCompany.setListedStatus(null); } if (!Objects.equal(updatedCompany.getListedRegion(), newCompany.getListedRegion())) { changedInfo.put(ChangedInfoKeys.companyListedRegion(), updatedCompany.getListedRegion()); updatedCompany.setListedRegion(null); } if (!Objects.equal(updatedCompany.getTicker(), newCompany.getTicker())) { changedInfo.put(ChangedInfoKeys.companyTicker(), updatedCompany.getTicker()); updatedCompany.setTicker(null); } } if (!changedInfo.isEmpty()) { supplierInfoChangedDto.setChanged(true); supplierInfoChangedDto.setChangedInfo(changedInfo); } return supplierInfoChangedDto; }