Java Code Examples for org.restlet.representation.StringRepresentation#setMediaType()
The following examples show how to use
org.restlet.representation.StringRepresentation#setMediaType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PlatformDeletePropertiesResource.java From scava with Eclipse Public License 2.0 | 6 votes |
@Delete public Representation deletePlatformProperties() { Platform platform = Platform.getInstance(); String key = (String) getRequest().getAttributes().get("key"); System.out.println("Delete platform properties ..."); ProjectRepository projectRepo = platform.getProjectRepositoryManager().getProjectRepository(); Properties properties = projectRepo.getProperties().findOneByKey(key); if (properties != null) { projectRepo.getProperties().remove(properties); platform.getProjectRepositoryManager().getProjectRepository().getProperties().sync(); } StringRepresentation rep = new StringRepresentation(properties.getDbObject().toString()); rep.setMediaType(MediaType.APPLICATION_JSON); getResponse().setStatus(Status.SUCCESS_OK); return rep; }
Example 2
Source File: AnalysisTaskByAnalysisTaskResource.java From scava with Eclipse Public License 2.0 | 6 votes |
@Override public Representation doRepresent() { AnalysisTaskService service = platform.getAnalysisRepositoryManager().getTaskService(); String analysisTaskId = getQueryValue("analysisTaskId"); AnalysisTask analysisTask = service.getTaskByAnalysisTaskId(analysisTaskId); analysisTask.getDbObject().put("projectId", analysisTask.getProject().getProjectId()); List<Object> metricExecutions = new ArrayList<>(); for (MetricExecution metric : analysisTask.getMetricExecutions()) { Map<String, String> newMetric = new HashMap<>(); newMetric.put("metricProviderId", metric.getDbObject().get("metricProviderId").toString()); newMetric.put("projectId", metric.getDbObject().get("projectId").toString()); newMetric.put("lastExecutionDate", metric.getDbObject().get("lastExecutionDate").toString()); metricExecutions.add(newMetric); } analysisTask.getDbObject().put("metricExecutions", metricExecutions); StringRepresentation rep = new StringRepresentation(analysisTask.getDbObject().toString()); rep.setMediaType(MediaType.APPLICATION_JSON); getResponse().setStatus(Status.SUCCESS_OK); return rep; }
Example 3
Source File: PlatformPropertiesByKeyResource.java From scava with Eclipse Public License 2.0 | 6 votes |
@Override public Representation doRepresent(){ String key = (String) getRequest().getAttributes().get("key"); System.out.println("Get platform properties by key ..."); Properties properties = new Properties(); ProjectRepository projectRepo = platform.getProjectRepositoryManager().getProjectRepository(); for (Properties prop : projectRepo.getProperties()) { if (prop.getKey().equals(key)) properties = prop; } StringRepresentation rep = new StringRepresentation(properties.getDbObject().toString()); rep.setMediaType(MediaType.APPLICATION_JSON); getResponse().setStatus(Status.SUCCESS_OK); return rep; }
Example 4
Source File: FactoidListResource.java From scava with Eclipse Public License 2.0 | 6 votes |
public Representation doRepresent() { ArrayNode node = mapper.createArrayNode(); for (IMetricProvider imp : platform.getMetricProviderManager().getMetricProviders()) { if (imp instanceof AbstractFactoidMetricProvider) { ObjectNode factoid = mapper.createObjectNode(); factoid.put("id", imp.getIdentifier()); factoid.put("name", imp.getFriendlyName()); factoid.put("summary", imp.getSummaryInformation()); ArrayNode uses = mapper.createArrayNode(); if (imp.getIdentifiersOfUses() != null && imp.getIdentifiersOfUses().size() > 0) { for (String use : imp.getIdentifiersOfUses()) { uses.add(use); } } factoid.put("dependencies", uses); node.add(factoid); } } getResponse().setStatus(Status.SUCCESS_OK); StringRepresentation resp = new StringRepresentation(node.toString()); resp.setMediaType(MediaType.APPLICATION_JSON); return resp; }
Example 5
Source File: OAuthServerResource.java From DeviceConnect-Android with MIT License | 5 votes |
/** * Returns the representation of the given error. The format of the JSON * document is according to 5.2. Error Response. * * @param ex * Any OAuthException with error * @return The representation of the given error. */ public static Representation responseErrorRepresentation(OAuthException ex) { try { return new JsonRepresentation(ex.createErrorDocument()); } catch (JSONException e) { StringRepresentation r = new StringRepresentation( "{\"error\":\"server_error\",\"error_description:\":\"" + e.getLocalizedMessage() + "\"}"); r.setMediaType(MediaType.APPLICATION_JSON); return r; } }
Example 6
Source File: AnalysisDeleteTaskResource.java From scava with Eclipse Public License 2.0 | 5 votes |
@Delete public Representation deleteAnalysisTask() { Platform platform = Platform.getInstance(); AnalysisTaskService service = platform.getAnalysisRepositoryManager().getTaskService(); String analysisTaskId = getQueryValue("analysisTaskId"); AnalysisTask task = service.deleteAnalysisTask(analysisTaskId); StringRepresentation rep = new StringRepresentation(task.getDbObject().toString()); rep.setMediaType(MediaType.APPLICATION_JSON); getResponse().setStatus(Status.SUCCESS_OK); return rep; }
Example 7
Source File: ProjectEditionResource.java From scava with Eclipse Public License 2.0 | 5 votes |
@Put public Representation editProject(Representation entity) { try { Platform platform = Platform.getInstance(); ObjectMapper mapper = new ObjectMapper(); String j = entity.getText(); JsonNode json = mapper.readTree(j); String sortName = json.get("shortName").asText(); // Retrieve the older project ProjectRepository projectRepo = platform.getProjectRepositoryManager().getProjectRepository(); Project project = projectRepo.getProjects().findOneByShortName(sortName); if (project instanceof GitHubRepository) { this.editGithubProject(json, project); } else if (project instanceof GitLabRepository) { this.editGitlabProject(json, project); } else if (project instanceof EclipseProject) { this.editEclipseProject(json, project); } else { this.editProject(json, project); } platform.getProjectRepositoryManager().getProjectRepository().getProjects().sync(); getResponse().setStatus(Status.SUCCESS_CREATED); return new StringRepresentation(project.getDbObject().toString()); } catch (IOException e) { e.printStackTrace(); // TODO StringRepresentation rep = new StringRepresentation( "{\"status\":\"error\", \"message\" : \"" + e.getMessage() + "\"}"); rep.setMediaType(MediaType.APPLICATION_JSON); getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST); return rep; } }
Example 8
Source File: AnalysisTaskPushOnWorkerResource.java From scava with Eclipse Public License 2.0 | 5 votes |
@Override public Representation doRepresent() { AnalysisTaskService service = platform.getAnalysisRepositoryManager().getTaskService(); String analysisTaskId = getQueryValue("analysisTaskId"); String workerId = getQueryValue("workerId"); AnalysisTask task = service.executeTaskOnWorker(analysisTaskId, workerId); StringRepresentation rep = new StringRepresentation(task.getDbObject().toString()); rep.setMediaType(MediaType.APPLICATION_JSON); getResponse().setStatus(Status.SUCCESS_OK); return rep; }
Example 9
Source File: AnalysisDemoteTaskResource.java From scava with Eclipse Public License 2.0 | 5 votes |
@Override public Representation doRepresent() { AnalysisTaskService service = platform.getAnalysisRepositoryManager().getTaskService(); String analysisTaskId = getQueryValue("analysisTaskId"); AnalysisTask task = service.demoteTask(analysisTaskId); StringRepresentation rep = new StringRepresentation(task.getDbObject().toString()); rep.setMediaType(MediaType.APPLICATION_JSON); getResponse().setStatus(Status.SUCCESS_OK); return rep; }
Example 10
Source File: AnalysisTasksStatusByProjectResource.java From scava with Eclipse Public License 2.0 | 5 votes |
@Override public Representation doRepresent() { String globalStatus; AnalysisTaskService service = platform.getAnalysisRepositoryManager().getTaskService(); String projectId = (String) getRequest().getAttributes().get("projectid"); List<AnalysisTask> tasks = service.getAnalysisTasksByProject(projectId); String stat = "none"; for (AnalysisTask analysisTask : tasks) { if (analysisTask.getScheduling().getStatus().equals(AnalysisTaskStatus.COMPLETED.name()) || analysisTask.getScheduling().getStatus().equals(AnalysisTaskStatus.STOP.name())) { stat = "up-to-date"; } else if (analysisTask.getScheduling().getStatus().equals(AnalysisTaskStatus.ERROR.name())) { stat = "error"; break; } else { stat = "in-progress"; break; } } if (stat.equals("up-to-date")) { globalStatus = "{\"value\":\"up-to-date\"}"; } else if (stat.equals("in-progress")){ globalStatus = "{\"value\":\"in-progress\"}"; } else if (stat.equals("error")){ globalStatus = "{\"value\":\"error\"}"; } else { globalStatus = "{\"value\":\"none\"}"; } StringRepresentation rep = new StringRepresentation(globalStatus); rep.setMediaType(MediaType.APPLICATION_JSON); getResponse().setStatus(Status.SUCCESS_OK); return rep; }
Example 11
Source File: ProjectResource.java From scava with Eclipse Public License 2.0 | 5 votes |
public Representation doRepresent() { String projectId = (String) getRequest().getAttributes().get("projectid"); ProjectRepository projectRepo = platform.getProjectRepositoryManager().getProjectRepository(); // FIXME: This exclusion list needs to be somewhere... BasicDBObject ex = new BasicDBObject("executionInformation", 0); ex.put("storage", 0); ex.put("metricProviderData", 0); ex.put("_superTypes", 0); ex.put("_id", 0); // FIXME: Temporary solution to DBRefs not being expanded // How can we auto-expand and DBRefs when serialising? ex.put("licenses", 0); ex.put("persons", 0); ex.put("companies", 0); BasicDBObject query = new BasicDBObject("shortName", projectId); DBObject p = projectRepo.getProjects().getDbCollection().findOne(query, ex); if (p == null) { getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST); return Util.generateErrorMessageRepresentation(generateRequestJson(mapper, projectId), "No project was found with the requested name."); } try { StringRepresentation resp = new StringRepresentation(p.toString()); resp.setMediaType(MediaType.APPLICATION_JSON); return resp; } catch (Exception e) { e.printStackTrace(); getResponse().setStatus(Status.SERVER_ERROR_INTERNAL); return Util.generateErrorMessageRepresentation(generateRequestJson(mapper, projectId), "An error occurred when converting the project to JSON: " + e.getMessage()); } }
Example 12
Source File: AnalysisPromoteTaskResource.java From scava with Eclipse Public License 2.0 | 5 votes |
@Override public Representation doRepresent() { AnalysisTaskService service = platform.getAnalysisRepositoryManager().getTaskService(); String analysisTaskId = getQueryValue("analysisTaskId"); AnalysisTask task = service.promoteTask(analysisTaskId); StringRepresentation rep = new StringRepresentation(task.getDbObject().toString()); rep.setMediaType(MediaType.APPLICATION_JSON); getResponse().setStatus(Status.SUCCESS_OK); return rep; }
Example 13
Source File: MetricVisualisationResource.java From scava with Eclipse Public License 2.0 | 4 votes |
public Representation doRepresent() { String projectName = (String) getRequest().getAttributes().get("projectid"); String metricId = (String) getRequest().getAttributes().get("metricid"); String agg = getQueryValue("agg"); String start = getQueryValue("startDate"); String end = getQueryValue("endDate"); QueryBuilder builder = QueryBuilder.start(); if (agg != null && agg != "") { // builder.... // TODO } try { if (start != null && start != "") { builder.and("__datetime").greaterThanEquals(new Date(start).toJavaDate()); } if (end != null && end != "") { builder.and("__datetime").lessThanEquals(new Date(end).toJavaDate()); } } catch (ParseException e) { return Util.generateErrorMessageRepresentation(generateRequestJson(projectName, metricId), "Invalid date. Format must be YYYYMMDD."); } BasicDBObject query = (BasicDBObject) builder.get(); ProjectRepository projectRepo = platform.getProjectRepositoryManager().getProjectRepository(); Project project = projectRepo.getProjects().findOneByShortName(projectName); if (project == null) { getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST); return Util.generateErrorMessageRepresentation(generateRequestJson(projectName, metricId), "No project was found with the requested name."); } MetricVisualisationExtensionPointManager manager = MetricVisualisationExtensionPointManager.getInstance(); manager.getRegisteredVisualisations(); MetricVisualisation vis = manager.findVisualisationById(metricId); if (vis == null) { return Util.generateErrorMessageRepresentation(generateRequestJson(projectName, metricId), "No visualiser found with specified ID."); } DB db = platform.getMetricsRepository(project).getDb(); JsonNode visualisation = vis.visualise(db, query); StringRepresentation resp = new StringRepresentation(visualisation.toString()); resp.setMediaType(MediaType.APPLICATION_JSON); return resp; }
Example 14
Source File: Util.java From scava with Eclipse Public License 2.0 | 4 votes |
public static StringRepresentation createJsonRepresentation(String json) { StringRepresentation resp = new StringRepresentation(json); resp.setMediaType(MediaType.APPLICATION_JSON); return resp; }
Example 15
Source File: Util.java From scava with Eclipse Public License 2.0 | 4 votes |
public static Representation generateErrorMessageRepresentation(JsonNode request, String message) { JsonNode msg = generateErrorMessage(request, message); StringRepresentation rep = new StringRepresentation(msg.toString()); rep.setMediaType(MediaType.APPLICATION_JSON); return rep; }
Example 16
Source File: ProjectListResource.java From scava with Eclipse Public License 2.0 | 4 votes |
public Representation doRepresent() { // Ready query params String _page = getQueryValue("page"); String _size = getQueryValue("size"); ProjectRepository projectRepo = platform.getProjectRepositoryManager().getProjectRepository(); DBCursor cursor; if(_page != null && !"".equals(_page) && isInteger(_page) && _size != null && !"".equals(_size) && isInteger(_size)) { int page = Integer.valueOf(_page); int pageSize = Integer.valueOf(_size); cursor = projectRepo.getProjects().getDbCollection().find().skip(page*pageSize).limit(pageSize); } else { cursor = projectRepo.getProjects().getDbCollection().find(); } ArrayNode projects = mapper.createArrayNode(); while (cursor.hasNext()) { try { DBObject p = cursor.next(); p.removeField("storage"); p.removeField("metricProviderData"); p.removeField("_superTypes"); p.removeField("_id"); // FIXME: Temporary solution p.removeField("licenses"); p.removeField("persons"); projects.add(mapper.readTree(p.toString())); } catch (Exception e) { System.err.println("Error: " + e.getMessage()); ObjectNode m = mapper.createObjectNode(); m.put("apicall", "list-all-projects"); return Util.generateErrorMessageRepresentation(m, e.getMessage()); } } cursor.close(); StringRepresentation resp = new StringRepresentation(projects.toString()); resp.setMediaType(MediaType.APPLICATION_JSON); return resp; }
Example 17
Source File: Util.java From scava with Eclipse Public License 2.0 | 4 votes |
public static Representation generateErrorMessageRepresentation(JsonNode request, String message) { JsonNode msg = generateErrorMessage(request, message); StringRepresentation rep = new StringRepresentation(msg.toString()); rep.setMediaType(MediaType.APPLICATION_JSON); return rep; }
Example 18
Source File: Util.java From scava with Eclipse Public License 2.0 | 4 votes |
public static StringRepresentation createJsonRepresentation(String json) { StringRepresentation resp = new StringRepresentation(json); resp.setMediaType(MediaType.APPLICATION_JSON); return resp; }