33 */
44package org .ligoj .app .plugin .storage .owncloud ;
55
6- import java .io .IOException ;
7- import java .net .URI ;
8- import java .net .URISyntaxException ;
9- import java .text .Format ;
10- import java .util .List ;
11- import java .util .Map ;
12-
13- import jakarta .ws .rs .Consumes ;
14- import jakarta .ws .rs .GET ;
15- import jakarta .ws .rs .Path ;
16- import jakarta .ws .rs .PathParam ;
17- import jakarta .ws .rs .Produces ;
6+ import com .fasterxml .jackson .databind .ObjectMapper ;
7+ import jakarta .ws .rs .*;
188import jakarta .ws .rs .core .MediaType ;
19-
209import org .apache .commons .lang3 .ObjectUtils ;
2110import org .apache .commons .lang3 .StringUtils ;
11+ import org .apache .commons .lang3 .Strings ;
2212import org .ligoj .app .api .SubscriptionStatusWithData ;
2313import org .ligoj .app .plugin .storage .StorageResource ;
2414import org .ligoj .app .plugin .storage .StorageServicePlugin ;
3121import org .springframework .beans .factory .annotation .Value ;
3222import org .springframework .stereotype .Service ;
3323
34- import com .fasterxml .jackson .databind .ObjectMapper ;
24+ import java .io .IOException ;
25+ import java .net .URI ;
26+ import java .net .URISyntaxException ;
27+ import java .text .Format ;
28+ import java .util .List ;
29+ import java .util .Map ;
3530
3631/**
3732 * OwnCloud resource. Also see "index.php/apps/files/ajax/list.php" : My files
@@ -95,7 +90,7 @@ public void link(final int subscription) throws Exception {
9590 */
9691 private Directory validateProject (final Map <String , String > parameters ) throws IOException , URISyntaxException {
9792 // Get project's configuration
98- final int id = Integer .parseInt (ObjectUtils .defaultIfNull (parameters .get (PARAMETER_DIRECTORY ), "0" ));
93+ final int id = Integer .parseInt (ObjectUtils .getIfNull (parameters .get (PARAMETER_DIRECTORY ), "0" ));
9994 final Directory result = getDirectory (parameters , id );
10095
10196 if (result == null ) {
@@ -114,7 +109,7 @@ private Directory validateProject(final Map<String, String> parameters) throws I
114109 * @throws IOException When OwnCloud JSON content cannot be parsed.
115110 */
116111 private String validateAdminAccess (final Map <String , String > parameters ) throws IOException {
117- final String url = StringUtils .appendIfMissing (parameters .get (PARAMETER_URL ), "/" );
112+ final String url = Strings . CS .appendIfMissing (parameters .get (PARAMETER_URL ), "/" );
118113
119114 // Check access
120115 CurlProcessor .validateAndClose (url , PARAMETER_URL , "owncloud-connection" );
@@ -131,7 +126,7 @@ private String validateAdminAccess(final Map<String, String> parameters) throws
131126 * Return a OwnCloud's resource. Return <code>null</code> when the resource is not found.
132127 */
133128 private String getResource (final Map <String , String > parameters , final String resource ) {
134- return newProcessor (parameters ).get (StringUtils .appendIfMissing (parameters .get (PARAMETER_URL ), "/" ) + resource );
129+ return newProcessor (parameters ).get (Strings . CS .appendIfMissing (parameters .get (PARAMETER_URL ), "/" ) + resource );
135130 }
136131
137132 @ Override
@@ -147,7 +142,7 @@ public String getVersion(final Map<String, String> parameters) throws IOExceptio
147142 */
148143 private List <SharedDirectory > getDirectories (final Map <String , String > parameters ) throws IOException {
149144 return new ObjectMapper ()
150- .readValue (StringUtils . removeEnd (StringUtils .removeStart (StringUtils .defaultIfEmpty (
145+ .readValue (Strings . CS . removeEnd (Strings . CS .removeStart (StringUtils .defaultIfEmpty (
151146 getResource (parameters , "ocs/v1.php/apps/files_sharing/api/v1/shares?format=json" ),
152147 "{\" ocs\" :{\" data\" :[]}}" ), "{\" ocs\" :" ), "}" ), SharedDirectories .class )
153148 .getData ().stream ().filter (d -> "folder" .equals (d .getType ())).distinct ().toList ();
@@ -169,7 +164,7 @@ private Directory getDirectory(final Map<String, String> parameters, final int i
169164 // The, get the directory size from the content's size
170165 final String path = "index.php/apps/files/ajax/list.php?dir="
171166 + new URI ("http" , sharedDirectory .getPath (), "" ).toURL ().getPath ();
172- final String files = StringUtils . removeEnd (StringUtils .removeStart (
167+ final String files = Strings . CS . removeEnd (Strings . CS .removeStart (
173168 StringUtils .defaultIfEmpty (getResource (parameters , path ), "{\" data\" :{\" files\" :[]}}" ), "{\" data\" :" ),
174169 "}" );
175170 final Directory directory = new Directory ();
@@ -203,7 +198,7 @@ public List<Directory> findAllByName(@PathParam("node") final String node,
203198 .map (d -> {
204199 final Directory dir = new Directory ();
205200 dir .setId (d .getId ());
206- dir .setName (StringUtils .removeStart (d .getName (), "/" ));
201+ dir .setName (Strings . CS .removeStart (d .getName (), "/" ));
207202 return dir ;
208203 }).toList ();
209204 }
0 commit comments