Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*-
* #%L
* owncloud-spring-boot-starter
* %%
* Copyright (C) 2016 - 2017 by the original Authors
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* .
* #L%
*/
package software.coolstuff.springframework.owncloud.service.impl.rest;
import com.github.sardine.DavResource;
import com.github.sardine.Sardine;
import com.github.sardine.impl.SardineException;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.Lists;
import lombok.Builder;
import lombok.Data;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import org.apache.http.HttpStatus;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.client.ClientHttpRequest;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import software.coolstuff.springframework.owncloud.exception.resource.*;
import software.coolstuff.springframework.owncloud.model.OwncloudFileResource;
import software.coolstuff.springframework.owncloud.model.OwncloudQuota;
import software.coolstuff.springframework.owncloud.model.OwncloudResource;
import software.coolstuff.springframework.owncloud.service.api.OwncloudResourceService;
import software.coolstuff.springframework.owncloud.service.impl.OwncloudUtils;
import software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestProperties.ResourceServiceProperties.CacheProperties;
import javax.annotation.PostConstruct;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Stream;
@Slf4j
public class OwncloudRestResourceServiceImpl implements OwncloudResourceService, OwncloudRestService, OwncloudResolveRootUriService {
private static final String URI_SUFFIX = "/remote.php/dav/files/{username}/";
private static final String SLASH = "/";
private static final String QUOTE = "\"";
private final RestTemplate restTemplate;
private final OwncloudRestProperties properties;
private final SardineCacheLoader sardineCacheLoader;
private final OwncloudRestUserServiceExtension userService;
private final String rootUri;
private LoadingCache sardineCache;
public OwncloudRestResourceServiceImpl(
final RestTemplateBuilder builder,
final OwncloudRestProperties properties,
final SardineCacheLoader sardineCacheLoader,
final OwncloudRestUserServiceExtension userService) throws MalformedURLException {
this.properties = properties;
this.sardineCacheLoader = sardineCacheLoader;
this.userService = userService;
URL locationURL = OwncloudRestUtils.checkAndConvertLocation(properties.getLocation());
this.rootUri = appendOptionalSuffix(locationURL, URI_SUFFIX);
log.debug("Build the RestTemplate based on Root URI {}", rootUri);
restTemplate = builder
.requestFactory(HttpComponentsClientHttpRequestFactory.class)
.messageConverters(new ByteArrayHttpMessageConverter())
.rootUri(rootUri)
.build();
}
protected String appendOptionalSuffix(URL url, String suffix) {
if (StringUtils.isBlank(suffix)) {
return url.toString();
}
return StringUtils.stripEnd(url.toString(), SLASH) + SLASH + StringUtils.stripStart(suffix, SLASH);
}
@Override
public RestTemplate getRestTemplate() {
return restTemplate;
}
@PostConstruct
public void afterPropertiesSet() throws Exception {
log.debug("Build the Sardine Cache");
this.sardineCache = buildSardineCache();
}
protected LoadingCache buildSardineCache() {
CacheProperties cacheProperties = properties.getResourceService().getSardineCache();
CacheBuilder