@Test public void reindexUrlIsInvalid() { final Response response = this.component.reindex(HPO_ID, "htps: Assert.assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); }
@Override public Response reindex(String vocabularyId, String url) { String[] schemes = { "http", "https", "ftp", "file" }; UrlValidator urlValidator = new UrlValidator(schemes); if (url != null && !url.startsWith("jar:") && (!urlValidator.isValid(url) || !exists(url))) { return Response.status(Response.Status.BAD_REQUEST).build(); } if (!this.userIsAdmin()) { return Response.status(Response.Status.FORBIDDEN).build(); } Vocabulary vocabulary = this.vm.getVocabulary(vocabularyId); if (vocabulary == null) { return Response.status(Response.Status.NOT_FOUND).build(); } Response result; try { int reindexStatus = vocabulary.reindex(url); if (reindexStatus == 0) { final JSONObject responseMeta = new JSONObject().put(VERSION, vocabulary.getVersion()); result = Response.ok(responseMeta, MediaType.APPLICATION_JSON_TYPE).build(); } else if (reindexStatus == 1) { result = Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } else { result = Response.status(Response.Status.BAD_REQUEST).build(); } } catch (UnsupportedOperationException e) { result = Response.status(Response.Status.SERVICE_UNAVAILABLE).build(); } return result; }
DefaultVocabularyResource extends XWikiResource implements VocabularyResource { @Override public Response reindex(String vocabularyId, String url) { String[] schemes = { "http", "https", "ftp", "file" }; UrlValidator urlValidator = new UrlValidator(schemes); if (url != null && !url.startsWith("jar:") && (!urlValidator.isValid(url) || !exists(url))) { return Response.status(Response.Status.BAD_REQUEST).build(); } if (!this.userIsAdmin()) { return Response.status(Response.Status.FORBIDDEN).build(); } Vocabulary vocabulary = this.vm.getVocabulary(vocabularyId); if (vocabulary == null) { return Response.status(Response.Status.NOT_FOUND).build(); } Response result; try { int reindexStatus = vocabulary.reindex(url); if (reindexStatus == 0) { final JSONObject responseMeta = new JSONObject().put(VERSION, vocabulary.getVersion()); result = Response.ok(responseMeta, MediaType.APPLICATION_JSON_TYPE).build(); } else if (reindexStatus == 1) { result = Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } else { result = Response.status(Response.Status.BAD_REQUEST).build(); } } catch (UnsupportedOperationException e) { result = Response.status(Response.Status.SERVICE_UNAVAILABLE).build(); } return result; } }
DefaultVocabularyResource extends XWikiResource implements VocabularyResource { @Override public Response reindex(String vocabularyId, String url) { String[] schemes = { "http", "https", "ftp", "file" }; UrlValidator urlValidator = new UrlValidator(schemes); if (url != null && !url.startsWith("jar:") && (!urlValidator.isValid(url) || !exists(url))) { return Response.status(Response.Status.BAD_REQUEST).build(); } if (!this.userIsAdmin()) { return Response.status(Response.Status.FORBIDDEN).build(); } Vocabulary vocabulary = this.vm.getVocabulary(vocabularyId); if (vocabulary == null) { return Response.status(Response.Status.NOT_FOUND).build(); } Response result; try { int reindexStatus = vocabulary.reindex(url); if (reindexStatus == 0) { final JSONObject responseMeta = new JSONObject().put(VERSION, vocabulary.getVersion()); result = Response.ok(responseMeta, MediaType.APPLICATION_JSON_TYPE).build(); } else if (reindexStatus == 1) { result = Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } else { result = Response.status(Response.Status.BAD_REQUEST).build(); } } catch (UnsupportedOperationException e) { result = Response.status(Response.Status.SERVICE_UNAVAILABLE).build(); } return result; }  }
DefaultVocabularyResource extends XWikiResource implements VocabularyResource { @Override public Response reindex(String vocabularyId, String url) { String[] schemes = { "http", "https", "ftp", "file" }; UrlValidator urlValidator = new UrlValidator(schemes); if (url != null && !url.startsWith("jar:") && (!urlValidator.isValid(url) || !exists(url))) { return Response.status(Response.Status.BAD_REQUEST).build(); } if (!this.userIsAdmin()) { return Response.status(Response.Status.FORBIDDEN).build(); } Vocabulary vocabulary = this.vm.getVocabulary(vocabularyId); if (vocabulary == null) { return Response.status(Response.Status.NOT_FOUND).build(); } Response result; try { int reindexStatus = vocabulary.reindex(url); if (reindexStatus == 0) { final JSONObject responseMeta = new JSONObject().put(VERSION, vocabulary.getVersion()); result = Response.ok(responseMeta, MediaType.APPLICATION_JSON_TYPE).build(); } else if (reindexStatus == 1) { result = Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } else { result = Response.status(Response.Status.BAD_REQUEST).build(); } } catch (UnsupportedOperationException e) { result = Response.status(Response.Status.SERVICE_UNAVAILABLE).build(); } return result; }  @Override org.phenotips.vocabularies.rest.model.Vocabulary getVocabulary(String vocabularyId); @Override Response reindex(String vocabularyId, String url); }
DefaultVocabularyResource extends XWikiResource implements VocabularyResource { @Override public Response reindex(String vocabularyId, String url) { String[] schemes = { "http", "https", "ftp", "file" }; UrlValidator urlValidator = new UrlValidator(schemes); if (url != null && !url.startsWith("jar:") && (!urlValidator.isValid(url) || !exists(url))) { return Response.status(Response.Status.BAD_REQUEST).build(); } if (!this.userIsAdmin()) { return Response.status(Response.Status.FORBIDDEN).build(); } Vocabulary vocabulary = this.vm.getVocabulary(vocabularyId); if (vocabulary == null) { return Response.status(Response.Status.NOT_FOUND).build(); } Response result; try { int reindexStatus = vocabulary.reindex(url); if (reindexStatus == 0) { final JSONObject responseMeta = new JSONObject().put(VERSION, vocabulary.getVersion()); result = Response.ok(responseMeta, MediaType.APPLICATION_JSON_TYPE).build(); } else if (reindexStatus == 1) { result = Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } else { result = Response.status(Response.Status.BAD_REQUEST).build(); } } catch (UnsupportedOperationException e) { result = Response.status(Response.Status.SERVICE_UNAVAILABLE).build(); } return result; }  @Override org.phenotips.vocabularies.rest.model.Vocabulary getVocabulary(String vocabularyId); @Override Response reindex(String vocabularyId, String url);  }