PageRenderTime 53ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/core2/src/main/java/org/synbiohub/frontend/SynBioHubFrontend.java

http://github.com/SynBioDex/libSBOLj
Java | 3733 lines | 2213 code | 441 blank | 1079 comment | 130 complexity | cbd916f2495ee2d5415914759869196c MD5 | raw file
Possible License(s): Apache-2.0

Large files files are truncated, but you can click here to view the full file

  1. package org.synbiohub.frontend;
  2. import java.io.ByteArrayInputStream;
  3. import java.io.ByteArrayOutputStream;
  4. import java.io.File;
  5. import java.io.FileInputStream;
  6. import java.io.FileNotFoundException;
  7. import java.io.FileOutputStream;
  8. import java.io.IOException;
  9. import java.io.InputStream;
  10. import java.io.InputStreamReader;
  11. import java.io.OutputStream;
  12. import java.io.StringWriter;
  13. import java.io.UnsupportedEncodingException;
  14. import java.net.URI;
  15. import java.net.URLEncoder;
  16. import java.util.ArrayList;
  17. import java.util.List;
  18. import java.util.Set;
  19. import org.apache.commons.io.IOUtils;
  20. import org.apache.http.HttpEntity;
  21. import org.apache.http.HttpResponse;
  22. import org.apache.http.NameValuePair;
  23. import org.apache.http.client.HttpClient;
  24. import org.apache.http.client.config.RequestConfig;
  25. import org.apache.http.client.entity.UrlEncodedFormEntity;
  26. import org.apache.http.client.methods.HttpGet;
  27. import org.apache.http.client.methods.HttpPost;
  28. import org.apache.http.client.methods.HttpRequestBase;
  29. import org.apache.http.entity.ContentType;
  30. import org.apache.http.entity.mime.HttpMultipartMode;
  31. import org.apache.http.entity.mime.MultipartEntityBuilder;
  32. import org.apache.http.impl.client.HttpClientBuilder;
  33. import org.apache.http.impl.client.HttpClients;
  34. import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
  35. import org.apache.http.message.BasicNameValuePair;
  36. import org.json.simple.JSONArray;
  37. import org.json.simple.JSONObject;
  38. import org.json.simple.parser.JSONParser;
  39. import org.sbolstandard.core2.SBOLDocument;
  40. import org.sbolstandard.core2.SBOLReader;
  41. import org.sbolstandard.core2.SBOLValidationException;
  42. import org.sbolstandard.core2.SBOLWriter;
  43. import org.sbolstandard.core2.TopLevel;
  44. import com.google.gson.Gson;
  45. import com.google.gson.reflect.TypeToken;
  46. /**
  47. * Provides a Java API to SynBioHub instances.
  48. * @author James McLaughlin
  49. * @author Chris Myers
  50. *
  51. */
  52. public class SynBioHubFrontend
  53. {
  54. PoolingHttpClientConnectionManager connectionManager;
  55. HttpClient client;
  56. String backendUrl;
  57. String uriPrefix;
  58. String user = "";
  59. String username = null;
  60. /**
  61. * Creates an instance of the SynBioHub API.
  62. * @param backendUrl - URL for the SynBioHub instance.
  63. * @param uriPrefix - prefix for all URIs stored in this repository
  64. */
  65. public SynBioHubFrontend(String backendUrl, String uriPrefix)
  66. {
  67. this.backendUrl = backendUrl;
  68. this.uriPrefix = uriPrefix;
  69. connectionManager = new PoolingHttpClientConnectionManager();
  70. client = HttpClients.custom().setConnectionManager(connectionManager).build();
  71. }
  72. /**
  73. * Creates an instance of the SynBioHub API.
  74. * @param backendUrl - URL for the SynBioHub instance.
  75. */
  76. public SynBioHubFrontend(String backendUrl)
  77. {
  78. this.backendUrl = backendUrl;
  79. this.uriPrefix = backendUrl;
  80. connectionManager = new PoolingHttpClientConnectionManager();
  81. client = HttpClients.custom().setConnectionManager(connectionManager).build();
  82. }
  83. /**
  84. * Creates an instance of the SynBioHub API.
  85. * @param backendUrl - URL for the SynBioHub instance.
  86. * @param timeout - timeout for connections in seconds
  87. */
  88. public SynBioHubFrontend(String backendUrl,int timeout)
  89. {
  90. this.backendUrl = backendUrl;
  91. this.uriPrefix = backendUrl;
  92. connectionManager = new PoolingHttpClientConnectionManager();
  93. // client = HttpClients.custom().setConnectionManager(connectionManager).build();
  94. RequestConfig config = RequestConfig.custom()
  95. .setConnectTimeout(timeout * 1000)
  96. .setConnectionRequestTimeout(timeout * 1000)
  97. .setSocketTimeout(timeout * 1000).build();
  98. client = HttpClientBuilder.create().setDefaultRequestConfig(config).build();
  99. }
  100. /**
  101. * Creates an instance of the SynBioHub API.
  102. * @param backendUrl - URL for the SynBioHub instance.
  103. * @param uriPrefix - prefix for all URIs stored in this repository
  104. * @param timeout - timeout for connections in seconds
  105. */
  106. public SynBioHubFrontend(String backendUrl, String uriPrefix, int timeout)
  107. {
  108. this.backendUrl = backendUrl;
  109. this.uriPrefix = uriPrefix;
  110. connectionManager = new PoolingHttpClientConnectionManager();
  111. RequestConfig config = RequestConfig.custom()
  112. .setConnectTimeout(timeout * 1000)
  113. .setConnectionRequestTimeout(timeout * 1000)
  114. .setSocketTimeout(timeout * 1000).build();
  115. client = HttpClientBuilder.create().setDefaultRequestConfig(config).build();
  116. }
  117. /**
  118. * Returns the URL for the SynBioHub instance.
  119. * @return the URL for the SynBioHub instance.
  120. */
  121. public String getBackendUrl()
  122. {
  123. return this.backendUrl;
  124. }
  125. /**
  126. * Return the total number of objects of a specified type in the repository.
  127. *
  128. * @return the total number of objects of a specified type in the repository.
  129. *
  130. * @param objectType The object type to count
  131. * (Collection, ComponentDefinition, Sequence, ModuleDefinition, Model, etc.).
  132. *
  133. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  134. */
  135. public int getCount(String objectType) throws SynBioHubException
  136. {
  137. return fetchCount(backendUrl + "/" + objectType + "/count");
  138. }
  139. /**
  140. * Retrieve SBOL TopLevel object from a SynBioHub instance using its URI.
  141. *
  142. * @param topLevelUri The URI of the SBOL TopLevel
  143. *
  144. * @return A libSBOLj TopLevel instance corresponding to the TopLevel
  145. *
  146. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  147. */
  148. public SBOLDocument getSBOL(URI topLevelUri) throws SynBioHubException
  149. {
  150. return getSBOL(topLevelUri,true);
  151. }
  152. /**
  153. * Retrieve SBOL TopLevel object from a SynBioHub instance using its URI.
  154. *
  155. * @param topLevelUri The URI of the SBOL TopLevel
  156. * @param recursive indicates if the complete SBOL document should be fetched recursively
  157. *
  158. * @return A libSBOLj TopLevel instance corresponding to the TopLevel
  159. *
  160. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  161. */
  162. public SBOLDocument getSBOL(URI topLevelUri,boolean recursive) throws SynBioHubException
  163. {
  164. if (topLevelUri==null) return null;
  165. if (!topLevelUri.toString().startsWith(uriPrefix)) {
  166. throw new SynBioHubException("Object URI does not start with correct URI prefix for this repository.");
  167. }
  168. String url = topLevelUri + "/sbol";
  169. if (!recursive) {
  170. url = topLevelUri + "/sbolnr";
  171. }
  172. url = url.replace(uriPrefix, backendUrl);
  173. try {
  174. SBOLDocument document = fetchFromSynBioHub(url);
  175. return document;
  176. } catch (NotFoundException e) {
  177. return null;
  178. }
  179. }
  180. /**
  181. * Retrieve a GFF3 version of a topLevel object from a SynBioHub instance using its URI,
  182. * and save to the path provided.
  183. *
  184. * @param topLevelURI The URI of the SBOL Attachment object
  185. * @param path The path to store the downloaded attachment
  186. * @return the name of the file being downloaded
  187. *
  188. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  189. * @throws IOException if there is an I/O error
  190. */
  191. public String getGFF3(URI topLevelURI, String path) throws SynBioHubException, IOException
  192. {
  193. if (!topLevelURI.toString().startsWith(uriPrefix)) {
  194. throw new SynBioHubException("Object URI does not start with correct URI prefix for this repository.");
  195. }
  196. String url = topLevelURI + "/gff";
  197. url = url.replace(uriPrefix, backendUrl);
  198. return fetchContentSaveToFile(url,null,path);
  199. }
  200. /**
  201. * Retrieve a GFF3 version of a topLevel object from a SynBioHub instance using its URI,
  202. * and save into the provided output stream.
  203. *
  204. * @param topLevelURI The URI of the SBOL Attachment object
  205. * @param outputStream The output stream to store the downloaded attachment
  206. * @return the name of the file being downloaded
  207. *
  208. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  209. * @throws IOException if there is an I/O error
  210. */
  211. public String getGFF3(URI topLevelURI, OutputStream outputStream) throws SynBioHubException, IOException
  212. {
  213. if (!topLevelURI.toString().startsWith(uriPrefix)) {
  214. throw new SynBioHubException("Object URI does not start with correct URI prefix for this repository.");
  215. }
  216. String url = topLevelURI + "/gff";
  217. url = url.replace(uriPrefix, backendUrl);
  218. return fetchContentSaveToFile(url,outputStream,null);
  219. }
  220. /**
  221. * Retrieve a GenBank version of a topLevel object from a SynBioHub instance using its URI,
  222. * and save to the path provided.
  223. *
  224. * @param topLevelURI The URI of the SBOL Attachment object
  225. * @param path The path to store the downloaded attachment
  226. * @return the name of the file being downloaded
  227. *
  228. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  229. * @throws IOException if there is an I/O error
  230. */
  231. public String getGenBank(URI topLevelURI, String path) throws SynBioHubException, IOException
  232. {
  233. if (!topLevelURI.toString().startsWith(uriPrefix)) {
  234. throw new SynBioHubException("Object URI does not start with correct URI prefix for this repository.");
  235. }
  236. String url = topLevelURI + "/gb";
  237. url = url.replace(uriPrefix, backendUrl);
  238. return fetchContentSaveToFile(url,null,path);
  239. }
  240. /**
  241. * Retrieve a GenBank version of a topLevel object from a SynBioHub instance using its URI,
  242. * and save into the provided output stream.
  243. *
  244. * @param topLevelURI The URI of the SBOL Attachment object
  245. * @param outputStream The output stream to store the downloaded attachment
  246. * @return the name of the file being downloaded
  247. *
  248. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  249. * @throws IOException if there is an I/O error
  250. */
  251. public String getGenBank(URI topLevelURI, OutputStream outputStream) throws SynBioHubException, IOException
  252. {
  253. if (!topLevelURI.toString().startsWith(uriPrefix)) {
  254. throw new SynBioHubException("Object URI does not start with correct URI prefix for this repository.");
  255. }
  256. String url = topLevelURI + "/gb";
  257. url = url.replace(uriPrefix, backendUrl);
  258. return fetchContentSaveToFile(url,outputStream,null);
  259. }
  260. /**
  261. * Retrieve a FASTA version of a topLevel object from a SynBioHub instance using its URI,
  262. * and save to the path provided.
  263. *
  264. * @param topLevelURI The URI of the SBOL Attachment object
  265. * @param path The path to store the downloaded attachment
  266. * @return the name of the file being downloaded
  267. *
  268. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  269. * @throws IOException if there is an I/O error
  270. */
  271. public String getFASTA(URI topLevelURI, String path) throws SynBioHubException, IOException
  272. {
  273. if (!topLevelURI.toString().startsWith(uriPrefix)) {
  274. throw new SynBioHubException("Object URI does not start with correct URI prefix for this repository.");
  275. }
  276. String url = topLevelURI + "/fasta";
  277. url = url.replace(uriPrefix, backendUrl);
  278. return fetchContentSaveToFile(url,null,path);
  279. }
  280. /**
  281. * Retrieve a GenBank version of a topLevel object from a SynBioHub instance using its URI,
  282. * and save into the provided output stream.
  283. *
  284. * @param topLevelURI The URI of the SBOL Attachment object
  285. * @param outputStream The output stream to store the downloaded attachment
  286. * @return the name of the file being downloaded
  287. *
  288. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  289. * @throws IOException if there is an I/O error
  290. */
  291. public String getFASTA(URI topLevelURI, OutputStream outputStream) throws SynBioHubException, IOException
  292. {
  293. if (!topLevelURI.toString().startsWith(uriPrefix)) {
  294. throw new SynBioHubException("Object URI does not start with correct URI prefix for this repository.");
  295. }
  296. String url = topLevelURI + "/fasta";
  297. url = url.replace(uriPrefix, backendUrl);
  298. return fetchContentSaveToFile(url,outputStream,null);
  299. }
  300. /**
  301. * Retrieve a JSON version of a topLevel object from a SynBioHub instance using its URI,
  302. * and save to the path provided.
  303. *
  304. * @param topLevelURI The URI of the SBOL Attachment object
  305. * @param path The path to store the downloaded attachment
  306. * @return the name of the file being downloaded
  307. *
  308. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  309. * @throws IOException if there is an I/O error
  310. */
  311. public String getJSON(URI topLevelURI, String path) throws SynBioHubException, IOException
  312. {
  313. if (!topLevelURI.toString().startsWith(uriPrefix)) {
  314. throw new SynBioHubException("Object URI does not start with correct URI prefix for this repository.");
  315. }
  316. String url = topLevelURI + "/summary";
  317. url = url.replace(uriPrefix, backendUrl);
  318. return fetchContentSaveToFile(url,null,path);
  319. }
  320. /**
  321. * Retrieve a JSON version of a topLevel object from a SynBioHub instance using its URI,
  322. * and save into the provided output stream.
  323. *
  324. * @param topLevelURI The URI of the SBOL Attachment object
  325. * @param outputStream The output stream to store the downloaded attachment
  326. * @return the name of the file being downloaded
  327. *
  328. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  329. * @throws IOException if there is an I/O error
  330. */
  331. public String getJSON(URI topLevelURI, OutputStream outputStream) throws SynBioHubException, IOException
  332. {
  333. if (!topLevelURI.toString().startsWith(uriPrefix)) {
  334. throw new SynBioHubException("Object URI does not start with correct URI prefix for this repository.");
  335. }
  336. String url = topLevelURI + "/summary";
  337. url = url.replace(uriPrefix, backendUrl);
  338. return fetchContentSaveToFile(url,outputStream,null);
  339. }
  340. /**
  341. * Retrieve metadata for a topLevel object from a SynBioHub instance using its URI,
  342. * and save to the path provided.
  343. *
  344. * @param topLevelURI The URI of the SBOL Attachment object
  345. * @param path The path to store the downloaded attachment
  346. * @return the name of the file being downloaded
  347. *
  348. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  349. * @throws IOException if there is an I/O error
  350. */
  351. public String getMetadata(URI topLevelURI, String path) throws SynBioHubException, IOException
  352. {
  353. if (!topLevelURI.toString().startsWith(uriPrefix)) {
  354. throw new SynBioHubException("Object URI does not start with correct URI prefix for this repository.");
  355. }
  356. String url = topLevelURI + "/metadata";
  357. url = url.replace(uriPrefix, backendUrl);
  358. return fetchContentSaveToFile(url,null,path);
  359. }
  360. /**
  361. * Retrieve metadata for a topLevel object from a SynBioHub instance using its URI,
  362. * and save into the provided output stream.
  363. *
  364. * @param topLevelURI The URI of the SBOL Attachment object
  365. * @param outputStream The output stream to store the downloaded attachment
  366. * @return the name of the file being downloaded
  367. *
  368. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  369. * @throws IOException if there is an I/O error
  370. */
  371. public String getMetadata(URI topLevelURI, OutputStream outputStream) throws SynBioHubException, IOException
  372. {
  373. if (!topLevelURI.toString().startsWith(uriPrefix)) {
  374. throw new SynBioHubException("Object URI does not start with correct URI prefix for this repository.");
  375. }
  376. String url = topLevelURI + "/metadata";
  377. url = url.replace(uriPrefix, backendUrl);
  378. return fetchContentSaveToFile(url,outputStream,null);
  379. }
  380. /**
  381. * Retrieve a COMBINE Archive version of a topLevel object from a SynBioHub instance using its URI,
  382. * and save to the path provided.
  383. *
  384. * @param topLevelURI The URI of the SBOL Attachment object
  385. * @param path The path to store the downloaded attachment
  386. * @return the name of the file being downloaded
  387. *
  388. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  389. * @throws IOException if there is an I/O error
  390. */
  391. public String getArchive(URI topLevelURI, String path) throws SynBioHubException, IOException
  392. {
  393. if (!topLevelURI.toString().startsWith(uriPrefix)) {
  394. throw new SynBioHubException("Object URI does not start with correct URI prefix for this repository.");
  395. }
  396. String url = topLevelURI + "/omex";
  397. url = url.replace(uriPrefix, backendUrl);
  398. return fetchContentSaveToFile(url,null,path);
  399. }
  400. /**
  401. * Retrieve a COMBINE Archive version of a topLevel object from a SynBioHub instance using its URI,
  402. * and save into the provided output stream.
  403. *
  404. * @param topLevelURI The URI of the SBOL Attachment object
  405. * @param outputStream The output stream to store the downloaded attachment
  406. * @return the name of the file being downloaded
  407. *
  408. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  409. * @throws IOException if there is an I/O error
  410. */
  411. public String getArchive(URI topLevelURI, OutputStream outputStream) throws SynBioHubException, IOException
  412. {
  413. if (!topLevelURI.toString().startsWith(uriPrefix)) {
  414. throw new SynBioHubException("Object URI does not start with correct URI prefix for this repository.");
  415. }
  416. String url = topLevelURI + "/omex";
  417. url = url.replace(uriPrefix, backendUrl);
  418. return fetchContentSaveToFile(url,outputStream,null);
  419. }
  420. /**
  421. * Retrieve an attachment from a SynBioHub instance using its URI,
  422. * and save to the path provided.
  423. *
  424. * @param attachmentUri The URI of the SBOL Attachment object
  425. * @param path The path to store the downloaded attachment
  426. * @return the name of the file being downloaded
  427. *
  428. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  429. * @throws IOException if there is an I/O error
  430. */
  431. public String getAttachment(URI attachmentUri, String path) throws SynBioHubException, IOException
  432. {
  433. if (!attachmentUri.toString().startsWith(uriPrefix)) {
  434. throw new SynBioHubException("Object URI does not start with correct URI prefix for this repository.");
  435. }
  436. String url = attachmentUri + "/download";
  437. url = url.replace(uriPrefix, backendUrl);
  438. return fetchContentSaveToFile(url,null,path);
  439. }
  440. /**
  441. * Retrieve an attachment from a SynBioHub instance using its URI,
  442. * and save into the provided output stream.
  443. *
  444. * @param attachmentUri The URI of the SBOL Attachment object
  445. * @param outputStream The output stream to store the downloaded attachment
  446. * @return the name of the file being downloaded
  447. *
  448. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  449. * @throws IOException if there is an I/O error
  450. */
  451. public String getAttachment(URI attachmentUri, OutputStream outputStream) throws SynBioHubException, IOException
  452. {
  453. if (!attachmentUri.toString().startsWith(uriPrefix)) {
  454. throw new SynBioHubException("Object URI does not start with correct URI prefix for this repository.");
  455. }
  456. String url = attachmentUri + "/download";
  457. url = url.replace(uriPrefix, backendUrl);
  458. return fetchContentSaveToFile(url,outputStream,null);
  459. }
  460. /**
  461. * Remove SBOL Collection from a SynBioHub instance using its URI.
  462. *
  463. * @param topLevelUri The URI of the SBOL Collection
  464. *
  465. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  466. */
  467. public void removeCollection(URI topLevelUri) throws SynBioHubException
  468. {
  469. if (!topLevelUri.toString().startsWith(uriPrefix)) {
  470. throw new SynBioHubException("Object URI does not start with correct URI prefix for this repository.");
  471. }
  472. String url = topLevelUri + "/removeCollection";
  473. url = url.replace(uriPrefix, backendUrl);
  474. removeFromSynBioHub(url);
  475. }
  476. /**
  477. * Remove SBOL TopLevel object from a SynBioHub instance using its URI.
  478. *
  479. * @param topLevelUri The URI of the SBOL TopLevel
  480. *
  481. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  482. */
  483. public void removeSBOL(URI topLevelUri) throws SynBioHubException
  484. {
  485. if (!topLevelUri.toString().startsWith(uriPrefix)) {
  486. throw new SynBioHubException("Object URI does not start with correct URI prefix for this repository.");
  487. }
  488. String url = topLevelUri + "/remove";
  489. url = url.replace(uriPrefix, backendUrl);
  490. removeFromSynBioHub(url);
  491. }
  492. /**
  493. * Remove SBOL TopLevel object from a SynBioHub instance using its URI,
  494. * but leave references to this object, since it is going to be replaced.
  495. *
  496. * @param topLevelUri The URI of the SBOL TopLevel
  497. *
  498. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  499. */
  500. public void replaceSBOL(URI topLevelUri) throws SynBioHubException
  501. {
  502. if (!topLevelUri.toString().startsWith(uriPrefix)) {
  503. throw new SynBioHubException("Object URI does not start with correct URI prefix for this repository.");
  504. }
  505. String url = topLevelUri + "/replace";
  506. url = url.replace(uriPrefix, backendUrl);
  507. removeFromSynBioHub(url);
  508. }
  509. /**
  510. * Search the default store for ComponentDefinition instances matching a name and/or a set of roles
  511. *
  512. * @param name The dcterms:title to search for, or null
  513. * @param roles A set of role URIs to search for, or null
  514. * @param types A set of type URIs to search for, or null
  515. * @param collections A set of Collection URIs to search for, or null
  516. * @param offset The offset of the results to begin at, or null to begin at 0
  517. * @param limit The maximum number of results to return, or null to return all results
  518. *
  519. * @return An ArrayList of ComponentDefinitionMetaData objects with a summary of all matching ComponentDefinitions.
  520. *
  521. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  522. */
  523. public ArrayList<IdentifiedMetadata> getMatchingComponentDefinitionMetadata(String name, Set<URI> roles,
  524. Set<URI> types, Set<URI> collections, Integer offset, Integer limit)
  525. throws SynBioHubException
  526. {
  527. SearchQuery query = new SearchQuery();
  528. query.setOffset(offset);
  529. query.setLimit(limit);
  530. SearchCriteria objectCriteria = new SearchCriteria();
  531. objectCriteria.setKey("objectType");
  532. objectCriteria.setValue("ComponentDefinition");
  533. query.addCriteria(objectCriteria);
  534. if (roles != null) {
  535. for(URI uri : roles)
  536. {
  537. SearchCriteria roleCriteria = new SearchCriteria();
  538. roleCriteria.setKey("role");
  539. roleCriteria.setValue(uri.toString());
  540. query.getCriteria().add(roleCriteria);
  541. }
  542. }
  543. if (types != null) {
  544. for(URI uri : types)
  545. {
  546. SearchCriteria typeCriteria = new SearchCriteria();
  547. typeCriteria.setKey("type");
  548. typeCriteria.setValue(uri.toString());
  549. query.getCriteria().add(typeCriteria);
  550. }
  551. }
  552. if (collections != null) {
  553. for(URI uri : collections)
  554. {
  555. SearchCriteria collectionCriteria = new SearchCriteria();
  556. collectionCriteria.setKey("collection");
  557. collectionCriteria.setValue(uri.toString());
  558. query.getCriteria().add(collectionCriteria);
  559. }
  560. }
  561. if(name != null)
  562. {
  563. SearchCriteria nameCriteria = new SearchCriteria();
  564. nameCriteria.setKey("name");
  565. nameCriteria.setValue(name);
  566. query.getCriteria().add(nameCriteria);
  567. }
  568. return search(query);
  569. }
  570. private String constructQueryURL(String url,SearchQuery query) {
  571. //query.offset = offset;
  572. //query.limit = limit;
  573. String textQuery = "";
  574. boolean first = true;
  575. for (SearchCriteria criteria : query.getCriteria()) {
  576. if (criteria.getKey().equals("objectType")) {
  577. url += encodeUri(criteria.getKey()+"="+criteria.getValue()+"&");
  578. continue;
  579. }
  580. if (criteria.getKey().equals("name")) {
  581. if (first) first = false;
  582. else textQuery = " ";
  583. textQuery = criteria.getValue();
  584. continue;
  585. }
  586. if (criteria.getKey().startsWith("http")) {
  587. url += encodeUri("<" + criteria.getKey() + ">=");
  588. } else {
  589. url += encodeUri(criteria.getKey()+"=");
  590. }
  591. if (criteria.getValue().startsWith("http")) {
  592. url += encodeUri("<"+criteria.getValue()+">&");
  593. } else {
  594. url += encodeUri("'"+criteria.getValue()+"'&");
  595. }
  596. }
  597. url += encodeUri(textQuery);
  598. if (query.getOffset()!=null && query.getLimit()!=null) {
  599. url += "/?offset="+query.getOffset() + "&" + "limit="+query.getLimit();
  600. } else if (query.getOffset()!=null) {
  601. url += "/?offset="+query.getOffset();
  602. } else if (query.getLimit()!=null) {
  603. url += "/?limit="+query.getLimit();
  604. }
  605. return url;
  606. }
  607. /**
  608. * Search this SynBioHub instance for objects matching a search query
  609. *
  610. * @param query the search query
  611. *
  612. * @return An ArrayList of MetaData for objects that match the specified search query
  613. *
  614. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  615. */
  616. public ArrayList<IdentifiedMetadata> search(SearchQuery query) throws SynBioHubException
  617. {
  618. String url = backendUrl + "/search/";
  619. //query.offset = offset;
  620. //query.limit = limit;
  621. url = constructQueryURL(url,query);
  622. //System.out.println(url);
  623. Gson gson = new Gson();
  624. HttpGet request = new HttpGet(url);
  625. request.setHeader("X-authorization", user);
  626. request.setHeader("Accept", "text/plain");
  627. try
  628. {
  629. HttpResponse response = client.execute(request);
  630. checkResponseCode(response);
  631. InputStream inputStream = response.getEntity().getContent();
  632. ArrayList<IdentifiedMetadata> metadataList = gson.fromJson(
  633. new InputStreamReader(inputStream),
  634. new TypeToken<ArrayList<IdentifiedMetadata>>(){}.getType());
  635. return metadataList;
  636. }
  637. catch (Exception e)
  638. {
  639. throw new SynBioHubException(e);
  640. }
  641. finally
  642. {
  643. request.releaseConnection();
  644. }
  645. }
  646. /**
  647. * Search this SynBioHub instance for objects matching a search query
  648. * and return the number of matches
  649. *
  650. * @param query the search query
  651. *
  652. * @return the number of objects matching a search query
  653. *
  654. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  655. */
  656. public int searchCount(SearchQuery query) throws SynBioHubException
  657. {
  658. String url = backendUrl + "/searchCount/";
  659. //query.offset = offset;
  660. //query.limit = limit;
  661. url = constructQueryURL(url,query);
  662. return fetchCount(url);
  663. }
  664. /**
  665. * Search the default store for Collections that are not members of any other Collections
  666. *
  667. * @return An ArrayList of CollectionMetaData objects with a summary of all matching Collections.
  668. *
  669. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  670. */
  671. public ArrayList<IdentifiedMetadata> getRootCollectionMetadata()
  672. throws SynBioHubException
  673. {
  674. String url = backendUrl + "/rootCollections";
  675. Gson gson = new Gson();
  676. HttpGet request = new HttpGet(url);
  677. request.setHeader("X-authorization", user);
  678. request.setHeader("Accept", "text/plain");
  679. try
  680. {
  681. HttpResponse response = client.execute(request);
  682. checkResponseCode(response);
  683. InputStream inputStream = response.getEntity().getContent();
  684. ArrayList<IdentifiedMetadata> metadataList = gson.fromJson(
  685. new InputStreamReader(inputStream),
  686. new TypeToken<ArrayList<IdentifiedMetadata>>(){}.getType());
  687. return metadataList;
  688. }
  689. catch (Exception e)
  690. {
  691. throw new SynBioHubException(e);
  692. }
  693. finally
  694. {
  695. request.releaseConnection();
  696. }
  697. }
  698. /**
  699. * Search the default store for submissions from the specified user
  700. *
  701. * @return An ArrayList of MetaData for all submissions for the specified user.
  702. *
  703. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  704. */
  705. public ArrayList<IdentifiedMetadata> getSubmissionsMetadata()
  706. throws SynBioHubException
  707. {
  708. String url = backendUrl + "/manage";
  709. Gson gson = new Gson();
  710. HttpGet request = new HttpGet(url);
  711. request.setHeader("X-authorization", user);
  712. request.setHeader("Accept", "text/plain");
  713. try
  714. {
  715. HttpResponse response = client.execute(request);
  716. checkResponseCode(response);
  717. InputStream inputStream = response.getEntity().getContent();
  718. ArrayList<IdentifiedMetadata> metadataList = gson.fromJson(
  719. new InputStreamReader(inputStream),
  720. new TypeToken<ArrayList<IdentifiedMetadata>>(){}.getType());
  721. return metadataList;
  722. }
  723. catch (Exception e)
  724. {
  725. throw new SynBioHubException(e);
  726. }
  727. finally
  728. {
  729. request.releaseConnection();
  730. }
  731. }
  732. /**
  733. * Search the default store for objects that are shared with the specified user
  734. *
  735. * @return An ArrayList of MetaData for all shared objects.
  736. *
  737. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  738. */
  739. public ArrayList<IdentifiedMetadata> getSharedMetadata()
  740. throws SynBioHubException
  741. {
  742. String url = backendUrl + "/shared";
  743. Gson gson = new Gson();
  744. HttpGet request = new HttpGet(url);
  745. request.setHeader("X-authorization", user);
  746. request.setHeader("Accept", "text/plain");
  747. try
  748. {
  749. HttpResponse response = client.execute(request);
  750. checkResponseCode(response);
  751. InputStream inputStream = response.getEntity().getContent();
  752. ArrayList<IdentifiedMetadata> metadataList = gson.fromJson(
  753. new InputStreamReader(inputStream),
  754. new TypeToken<ArrayList<IdentifiedMetadata>>(){}.getType());
  755. return metadataList;
  756. }
  757. catch (Exception e)
  758. {
  759. throw new SynBioHubException(e);
  760. }
  761. finally
  762. {
  763. request.releaseConnection();
  764. }
  765. }
  766. /**
  767. * Get configuration of a SynBioHub
  768. *
  769. * @return A JSON object of the configuration of a SynBioHub
  770. *
  771. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  772. */
  773. public JSONObject getConfig() throws SynBioHubException
  774. {
  775. return getConfig("");
  776. }
  777. /**
  778. * Get graphs in a SynBioHub
  779. *
  780. * @return A JSON array of the graphs in a SynBioHub
  781. *
  782. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  783. */
  784. public JSONArray getGraphs() throws SynBioHubException
  785. {
  786. if (user.equals("")) {
  787. Exception e = new Exception("Must be logged in to get the graphs.");
  788. throw new SynBioHubException(e);
  789. }
  790. String url = backendUrl + "/admin/graphs";
  791. HttpGet request = new HttpGet(url);
  792. request.setHeader("X-authorization", user);
  793. request.setHeader("Accept", "text/plain");
  794. try
  795. {
  796. HttpResponse response = client.execute(request);
  797. checkResponseCode(response);
  798. InputStream inputStream = response.getEntity().getContent();
  799. JSONParser parser = new JSONParser();
  800. JSONArray config = (JSONArray) parser.parse(inputStreamToString(inputStream));
  801. return config;
  802. }
  803. catch (Exception e)
  804. {
  805. throw new SynBioHubException(e);
  806. }
  807. finally
  808. {
  809. request.releaseConnection();
  810. }
  811. }
  812. /**
  813. * Get graphs in a SynBioHub
  814. *
  815. * @return A JSONObject of the graphs in a SynBioHub
  816. *
  817. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  818. */
  819. public JSONArray getLogs() throws SynBioHubException
  820. {
  821. if (user.equals("")) {
  822. Exception e = new Exception("Must be logged in to get the logs.");
  823. throw new SynBioHubException(e);
  824. }
  825. String url = backendUrl + "/admin/log";
  826. HttpGet request = new HttpGet(url);
  827. request.setHeader("X-authorization", user);
  828. request.setHeader("Accept", "text/plain");
  829. try
  830. {
  831. HttpResponse response = client.execute(request);
  832. checkResponseCode(response);
  833. InputStream inputStream = response.getEntity().getContent();
  834. JSONParser parser = new JSONParser();
  835. JSONArray config = (JSONArray) parser.parse(inputStreamToString(inputStream));
  836. return config;
  837. }
  838. catch (Exception e)
  839. {
  840. throw new SynBioHubException(e);
  841. }
  842. finally
  843. {
  844. request.releaseConnection();
  845. }
  846. }
  847. /**
  848. * Get mail configuration of a SynBioHub
  849. *
  850. * @return A JSON object of the mail configuration of a SynBioHub
  851. *
  852. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  853. */
  854. public JSONObject getMailConfig() throws SynBioHubException
  855. {
  856. return getConfig("mail");
  857. }
  858. /**
  859. * Set the mail configuration for a SynBioHub
  860. *
  861. * @param key SendGrid API Key
  862. * @param fromEmail SendGrid from Email
  863. *
  864. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  865. */
  866. public void setMailConfig(String key, String fromEmail) throws SynBioHubException
  867. {
  868. if (user.equals("")) {
  869. Exception e = new Exception("Must be logged in to set the mail configuration.");
  870. throw new SynBioHubException(e);
  871. }
  872. String url = backendUrl + "/admin/mail";
  873. HttpPost request = new HttpPost(url);
  874. request.setHeader("X-authorization", user);
  875. request.setHeader("Accept", "text/plain");
  876. List<NameValuePair> arguments = new ArrayList<>(4);
  877. arguments.add(new BasicNameValuePair("key", key));
  878. arguments.add(new BasicNameValuePair("fromEmail", fromEmail));
  879. try
  880. {
  881. request.setEntity(new UrlEncodedFormEntity(arguments));
  882. HttpResponse response = client.execute(request);
  883. checkResponseCode(response);
  884. }
  885. catch (Exception e)
  886. {
  887. //e.printStackTrace();
  888. throw new SynBioHubException(e);
  889. }
  890. finally
  891. {
  892. request.releaseConnection();
  893. }
  894. }
  895. /**
  896. * Get plugin configuration for a SynBioHub
  897. *
  898. * @return A JSON object of the plugin configuration for a SynBioHub
  899. *
  900. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  901. */
  902. public JSONObject getPluginsConfig() throws SynBioHubException
  903. {
  904. return getConfig("plugins");
  905. }
  906. /**
  907. * Edit a plugin configuration in a SynBioHub
  908. *
  909. * @param id Id of plugin
  910. * @param category Type of plugin (rendering, submit, download)
  911. * @param name Name of the plugin
  912. * @param pluginURL URL for the plugin
  913. *
  914. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  915. */
  916. public void editPluginConfig(int id, String category, String name, String pluginURL) throws SynBioHubException
  917. {
  918. id = id + 1;
  919. savePluginConfig(Integer.toString(id), category, name, pluginURL);
  920. }
  921. /**
  922. * Add a plugin configuration to a SynBioHub
  923. *
  924. * @param category Type of plugin (rendering, submit, download)
  925. * @param name Name of the plugin
  926. * @param pluginURL URL for the plugin
  927. *
  928. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  929. */
  930. public void addPluginConfig(String category, String name, String pluginURL) throws SynBioHubException
  931. {
  932. savePluginConfig("New", category, name, pluginURL);
  933. }
  934. /**
  935. * Save a plugin configuration to a SynBioHub
  936. *
  937. * @param id Id of plugin, if adding a plugin, id should be New
  938. * @param category Type of plugin (rendering, submit, download)
  939. * @param name Name of the plugin
  940. * @param pluginURL URL for the plugin
  941. *
  942. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  943. */
  944. private void savePluginConfig(String id, String category, String name, String pluginURL) throws SynBioHubException
  945. {
  946. if (user.equals("")) {
  947. Exception e = new Exception("Must be logged in to add a plugin configuration.");
  948. throw new SynBioHubException(e);
  949. }
  950. String url = backendUrl + "/admin/savePlugin";
  951. HttpPost request = new HttpPost(url);
  952. request.setHeader("X-authorization", user);
  953. request.setHeader("Accept", "text/plain");
  954. List<NameValuePair> arguments = new ArrayList<>(4);
  955. arguments.add(new BasicNameValuePair("id", id));
  956. arguments.add(new BasicNameValuePair("category", category));
  957. arguments.add(new BasicNameValuePair("name", name));
  958. arguments.add(new BasicNameValuePair("url", pluginURL));
  959. try
  960. {
  961. request.setEntity(new UrlEncodedFormEntity(arguments));
  962. HttpResponse response = client.execute(request);
  963. checkResponseCode(response);
  964. }
  965. catch (Exception e)
  966. {
  967. //e.printStackTrace();
  968. throw new SynBioHubException(e);
  969. }
  970. finally
  971. {
  972. request.releaseConnection();
  973. }
  974. }
  975. /**
  976. * Delete a plugin configuration to a SynBioHub
  977. *
  978. * @param id Id of plugin
  979. * @param category Type of plugin (rendering, submit, download)
  980. *
  981. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  982. */
  983. public void deletePluginConfig(int id, String category) throws SynBioHubException
  984. {
  985. if (user.equals("")) {
  986. Exception e = new Exception("Must be logged in to delete a plugin configuration.");
  987. throw new SynBioHubException(e);
  988. }
  989. String url = backendUrl + "/admin/deletePlugin";
  990. HttpPost request = new HttpPost(url);
  991. request.setHeader("X-authorization", user);
  992. request.setHeader("Accept", "text/plain");
  993. id = id + 1;
  994. List<NameValuePair> arguments = new ArrayList<>(4);
  995. arguments.add(new BasicNameValuePair("id", Integer.toString(id)));
  996. arguments.add(new BasicNameValuePair("category", category));
  997. try
  998. {
  999. request.setEntity(new UrlEncodedFormEntity(arguments));
  1000. HttpResponse response = client.execute(request);
  1001. checkResponseCode(response);
  1002. }
  1003. catch (Exception e)
  1004. {
  1005. //e.printStackTrace();
  1006. throw new SynBioHubException(e);
  1007. }
  1008. finally
  1009. {
  1010. request.releaseConnection();
  1011. }
  1012. }
  1013. /**
  1014. * Get registries configuration for a SynBioHub
  1015. *
  1016. * @return A JSON object of the registries configuration for a SynBioHub
  1017. *
  1018. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  1019. */
  1020. public JSONObject getRegistriesConfig() throws SynBioHubException
  1021. {
  1022. return getConfig("registries");
  1023. }
  1024. /**
  1025. * Save a registry configuration for a SynBioHub
  1026. *
  1027. * @param uriPrefix URI prefix for the registry
  1028. * @param registryURL URL for the registry
  1029. *
  1030. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  1031. */
  1032. public void saveRegistryConfig(String uriPrefix, String registryURL) throws SynBioHubException
  1033. {
  1034. if (user.equals("")) {
  1035. Exception e = new Exception("Must be logged in to save a registry configuration.");
  1036. throw new SynBioHubException(e);
  1037. }
  1038. String url = backendUrl + "/admin/saveRegistry";
  1039. HttpPost request = new HttpPost(url);
  1040. request.setHeader("X-authorization", user);
  1041. request.setHeader("Accept", "text/plain");
  1042. List<NameValuePair> arguments = new ArrayList<>(4);
  1043. arguments.add(new BasicNameValuePair("uri", uriPrefix));
  1044. arguments.add(new BasicNameValuePair("url", registryURL));
  1045. try
  1046. {
  1047. request.setEntity(new UrlEncodedFormEntity(arguments));
  1048. HttpResponse response = client.execute(request);
  1049. checkResponseCode(response);
  1050. }
  1051. catch (Exception e)
  1052. {
  1053. //e.printStackTrace();
  1054. throw new SynBioHubException(e);
  1055. }
  1056. finally
  1057. {
  1058. request.releaseConnection();
  1059. }
  1060. }
  1061. /**
  1062. * Delete a registry configuration in a SynBioHub
  1063. *
  1064. * @param uriPrefix URI prefix of the registry to delete
  1065. *
  1066. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  1067. */
  1068. public void deleteRegistryConfig(String uriPrefix) throws SynBioHubException
  1069. {
  1070. if (user.equals("")) {
  1071. Exception e = new Exception("Must be logged in to remove a registry configuration.");
  1072. throw new SynBioHubException(e);
  1073. }
  1074. String url = backendUrl + "/admin/deleteRegistry";
  1075. HttpPost request = new HttpPost(url);
  1076. request.setHeader("X-authorization", user);
  1077. request.setHeader("Accept", "text/plain");
  1078. List<NameValuePair> arguments = new ArrayList<>(4);
  1079. arguments.add(new BasicNameValuePair("uri", uriPrefix));
  1080. try
  1081. {
  1082. request.setEntity(new UrlEncodedFormEntity(arguments));
  1083. HttpResponse response = client.execute(request);
  1084. checkResponseCode(response);
  1085. }
  1086. catch (Exception e)
  1087. {
  1088. //e.printStackTrace();
  1089. throw new SynBioHubException(e);
  1090. }
  1091. finally
  1092. {
  1093. request.releaseConnection();
  1094. }
  1095. }
  1096. /**
  1097. * Update the administrator email configuration for a SynBioHub
  1098. *
  1099. * @param administratorEmail Administrator email address
  1100. *
  1101. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  1102. */
  1103. public void updateAdministratorEmailConfig(String administratorEmail) throws SynBioHubException
  1104. {
  1105. if (user.equals("")) {
  1106. Exception e = new Exception("Must be logged in to update the administrator email configuration.");
  1107. throw new SynBioHubException(e);
  1108. }
  1109. String url = backendUrl + "/admin/setAdministratorEmail";
  1110. HttpPost request = new HttpPost(url);
  1111. request.setHeader("X-authorization", user);
  1112. request.setHeader("Accept", "text/plain");
  1113. List<NameValuePair> arguments = new ArrayList<>(4);
  1114. arguments.add(new BasicNameValuePair("administratorEmail", administratorEmail));
  1115. try
  1116. {
  1117. request.setEntity(new UrlEncodedFormEntity(arguments));
  1118. HttpResponse response = client.execute(request);
  1119. checkResponseCode(response);
  1120. }
  1121. catch (Exception e)
  1122. {
  1123. //e.printStackTrace();
  1124. throw new SynBioHubException(e);
  1125. }
  1126. finally
  1127. {
  1128. request.releaseConnection();
  1129. }
  1130. }
  1131. /**
  1132. * Retrieve update from Web-of-Registries for a SynBioHub
  1133. *
  1134. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  1135. */
  1136. public void retreiveUpdateFromWebOfRegistries() throws SynBioHubException
  1137. {
  1138. if (user.equals("")) {
  1139. Exception e = new Exception("Must be logged in to retrieve update from Web-of-Registries.");
  1140. throw new SynBioHubException(e);
  1141. }
  1142. String url = backendUrl + "/admin/retrieveFromWebOfRegistries";
  1143. HttpPost request = new HttpPost(url);
  1144. request.setHeader("X-authorization", user);
  1145. request.setHeader("Accept", "text/plain");
  1146. try
  1147. {
  1148. HttpResponse response = client.execute(request);
  1149. checkResponseCode(response);
  1150. }
  1151. catch (Exception e)
  1152. {
  1153. //e.printStackTrace();
  1154. throw new SynBioHubException(e);
  1155. }
  1156. finally
  1157. {
  1158. request.releaseConnection();
  1159. }
  1160. }
  1161. /**
  1162. * Send request to join Web-of-Registries for a SynBioHub
  1163. *
  1164. * @param administratorEmail Administrator email address
  1165. * @param webOfRegistries URL for the Web-of-Registries
  1166. *
  1167. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  1168. */
  1169. public void requestToJoinWebOfRegistries(String administratorEmail, String webOfRegistries) throws SynBioHubException
  1170. {
  1171. if (user.equals("")) {
  1172. Exception e = new Exception("Must be logged in to send request to join Web-of-Registries.");
  1173. throw new SynBioHubException(e);
  1174. }
  1175. String url = backendUrl + "/admin/federate";
  1176. HttpPost request = new HttpPost(url);
  1177. request.setHeader("X-authorization", user);
  1178. request.setHeader("Accept", "text/plain");
  1179. List<NameValuePair> arguments = new ArrayList<>(4);
  1180. arguments.add(new BasicNameValuePair("administratorEmail", administratorEmail));
  1181. arguments.add(new BasicNameValuePair("webOfRegistries", webOfRegistries));
  1182. try
  1183. {
  1184. request.setEntity(new UrlEncodedFormEntity(arguments));
  1185. HttpResponse response = client.execute(request);
  1186. checkResponseCode(response);
  1187. }
  1188. catch (Exception e)
  1189. {
  1190. //e.printStackTrace();
  1191. throw new SynBioHubException(e);
  1192. }
  1193. finally
  1194. {
  1195. request.releaseConnection();
  1196. }
  1197. }
  1198. /**
  1199. * Get remotes configuration for a SynBioHub
  1200. *
  1201. * @return A JSON object of the remotes configuration for a SynBioHub
  1202. *
  1203. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  1204. */
  1205. public JSONObject getRemotesConfig() throws SynBioHubException
  1206. {
  1207. return getConfig("remotes");
  1208. }
  1209. /**
  1210. * Save a Benchling remote configuration for a SynBioHub
  1211. *
  1212. * @param id Id of the Benchling remote
  1213. * @param remoteURL URL for the Benchling remote
  1214. * @param benchlingApiToken API token for the Benchling remote
  1215. * @param rejectUnauthorized Check SSL certificate?
  1216. * @param folderPrefix Prefix to use for folders on Benchling
  1217. * @param sequenceSuffix Suffix to use for sequences found on Benchling
  1218. * @param defaultFolderId Default folder on Benchling to access
  1219. * @param isPublic Should the remote be visible publicly?
  1220. * @param rootCollectionDisplayId Display id for the root collection on the remote
  1221. * @param rootCollectionName Name for the root collection on the remote
  1222. * @param rootCollectionDescription Description for the root collection on the remote
  1223. *
  1224. * @throws SynBioHubException if there was an error communicating with the SynBioHub
  1225. */
  1226. public void saveBenchlingRemoteConfig(String id, String remoteURL, String benchlingApiToken,
  1227. boolean rejectUnauthorized, String folderPrefix, String sequenceSuffix, String defaultFolderId,
  1228. boolean isPublic, String rootCollectionDisplayId, String rootCollectionName,
  1229. String rootCollectionDescription) throws SynBioHubException
  1230. {
  1231. if (user.equals("")) {
  1232. Exception e = new Exception("Must be logged in to save a Benchling remote configuration.");
  1233. throw new SynBioHubException(e);
  1234. }
  1235. String url = backendUrl + "/admin/saveRemote";
  1236. HttpPost request = new HttpPost(url);
  1237. request.setHeader("X-authorization", user);
  1238. request.setHeader("Ac…

Large files files are truncated, but you can click here to view the full file