26
26
27
27
import com .alfresco .cloud .example .model .ContainerEntry ;
28
28
import com .alfresco .cloud .example .model .ContainerList ;
29
+ import com .alfresco .cloud .example .model .NetworkEntry ;
30
+ import com .alfresco .cloud .example .model .NetworkList ;
29
31
import com .alfresco .cloud .example .oauth .LocalServerReceiver ;
30
32
import com .alfresco .cloud .example .oauth .OAuth2ClientCredentials ;
31
33
import com .alfresco .cloud .example .oauth .VerificationCodeReceiver ;
53
55
*/
54
56
public abstract class BaseJavaExample {
55
57
56
- public static final String HOME_NETWORK = "alfresco.com" ;
57
58
public static final String SITE = "alfresco-api-demo" ;
58
59
public static final String SCOPE = "public_api" ;
59
60
public static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport ();
@@ -114,6 +115,8 @@ public void initialize(HttpRequest request) throws IOException {
114
115
} finally {
115
116
receiver .stop ();
116
117
}
118
+
119
+ System .out .println ("Done!" );
117
120
}
118
121
119
122
public void doExample (HttpRequestFactory requestFactory , Credential credential )
@@ -125,6 +128,8 @@ public Credential authorize(VerificationCodeReceiver receiver, String redirectUr
125
128
126
129
String code = receiver .waitForCode ();
127
130
131
+ //FileCredentialStore fcs = new FileCredentialStore("/var/tmp/oauthcreds", JSON_FACTORY);
132
+
128
133
AuthorizationCodeFlow codeFlow = new AuthorizationCodeFlow .Builder (
129
134
BearerToken .authorizationHeaderAccessMethod (),
130
135
HTTP_TRANSPORT ,
@@ -242,9 +247,9 @@ public Folder createFolder(Session cmisSession, String parentFolderId, String fo
242
247
243
248
Folder subFolder = null ;
244
249
try {
245
- // Making an assumption here that you probably wouldn't normally do
246
- subFolder = (Folder ) cmisSession .getObjectByPath (rootFolder .getPath () + "/" + folderName );
247
- System .out .println ("Folder already existed!" );
250
+ // Making an assumption here that you probably wouldn't normally do
251
+ subFolder = (Folder ) cmisSession .getObjectByPath (rootFolder .getPath () + "/" + folderName );
252
+ System .out .println ("Folder already existed!" );
248
253
} catch (CmisObjectNotFoundException onfe ) {
249
254
Map <String , Object > props = new HashMap <String , Object >();
250
255
props .put ("cmis:objectTypeId" , "cmis:folder" );
@@ -276,11 +281,27 @@ public String getRootFolderId(HttpRequestFactory requestFactory, String homeNetw
276
281
ContainerList containerList = request .execute ().parseAs (ContainerList .class );
277
282
String rootFolderId = null ;
278
283
for (ContainerEntry containerEntry : containerList .list .entries ) {
279
- if (containerEntry .entry .folderId .equals ("documentLibrary" )) {
280
- rootFolderId = containerEntry .entry .id ;
281
- break ;
282
- }
284
+ if (containerEntry .entry .folderId .equals ("documentLibrary" )) {
285
+ rootFolderId = containerEntry .entry .id ;
286
+ break ;
287
+ }
283
288
}
284
289
return rootFolderId ;
285
290
}
291
+
292
+ public String getHomeNetwork (HttpRequestFactory requestFactory , Credential credential ) throws IOException {
293
+ GenericUrl url = new GenericUrl (ALFRESCO_API_URL );
294
+
295
+ HttpRequest request = requestFactory .buildGetRequest (url );
296
+ NetworkList networkList = request .execute ().parseAs (NetworkList .class );
297
+ System .out .println ("Found " + networkList .list .pagination .totalItems + " networks." );
298
+ String homeNetwork = "" ;
299
+ for (NetworkEntry networkEntry : networkList .list .entries ) {
300
+ if (networkEntry .entry .homeNetwork ) {
301
+ homeNetwork = networkEntry .entry .id ;
302
+ }
303
+ }
304
+ System .out .println ("Your home network appears to be: " + homeNetwork );
305
+ return homeNetwork ;
306
+ }
286
307
}
0 commit comments