com.cedarsoftware.util.io.JsonWriter Java Examples
The following examples show how to use
com.cedarsoftware.util.io.JsonWriter.
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: IndexesResource.java From lumongo with Apache License 2.0 | 6 votes |
@GET @Produces({ MediaType.APPLICATION_JSON + ";charset=utf-8" }) public Response get(@Context Response response, @QueryParam(LumongoConstants.PRETTY) boolean pretty) { try { Lumongo.GetIndexesResponse getIndexesResponse = indexManager.getIndexes(Lumongo.GetIndexesRequest.newBuilder().build()); Document mongoDocument = new org.bson.Document(); mongoDocument.put("indexes", getIndexesResponse.getIndexNameList()); String docString = JSONSerializers.getStrict().serialize(mongoDocument); if (pretty) { docString = JsonWriter.formatJson(docString); } return Response.status(LumongoConstants.SUCCESS).entity(docString).build(); } catch (Exception e) { return Response.status(LumongoConstants.INTERNAL_ERROR).entity("Failed to get index names: " + e.getMessage()).build(); } }
Example #2
Source File: Flow2HandlerTest.java From cloudbreak with Apache License 2.0 | 6 votes |
@Test public void testRestartFlowNoRestartActionNoFlowChainId() throws TransactionExecutionException { ReflectionTestUtils.setField(underTest, "flowChainHandler", flowChainHandler); FlowLog flowLog = createFlowLog(null); Payload payload = new TestPayload(STACK_ID); flowLog.setPayload(JsonWriter.objectToJson(payload)); when(flowLogService.findFirstByFlowIdOrderByCreatedDesc(FLOW_ID)).thenReturn(Optional.of(flowLog)); when(applicationFlowInformation.getRestartableFlows()).thenReturn(List.of(HelloWorldFlowConfig.class)); HelloWorldFlowConfig helloWorldFlowConfig = new HelloWorldFlowConfig(); setUpFlowConfigCreateFlow(helloWorldFlowConfig); List<FlowConfiguration<?>> flowConfigs = Lists.newArrayList(helloWorldFlowConfig); ReflectionTestUtils.setField(underTest, "flowConfigs", flowConfigs); underTest.restartFlow(FLOW_ID); verify(flowChainHandler, never()).restoreFlowChain(FLOW_CHAIN_ID); verify(flowLogService, times(1)).terminate(STACK_ID, FLOW_ID); verify(defaultRestartAction, never()).restart(any(), any(), any(), any()); }
Example #3
Source File: Flow2HandlerTest.java From cloudbreak with Apache License 2.0 | 6 votes |
@Test public void testRestartFlowNoRestartAction() throws TransactionExecutionException { ReflectionTestUtils.setField(underTest, "flowChainHandler", flowChainHandler); FlowLog flowLog = createFlowLog(FLOW_CHAIN_ID); Payload payload = new TestPayload(STACK_ID); flowLog.setPayload(JsonWriter.objectToJson(payload)); when(flowLogService.findFirstByFlowIdOrderByCreatedDesc(FLOW_ID)).thenReturn(Optional.of(flowLog)); when(applicationFlowInformation.getRestartableFlows()).thenReturn(List.of(HelloWorldFlowConfig.class)); HelloWorldFlowConfig helloWorldFlowConfig = new HelloWorldFlowConfig(); setUpFlowConfigCreateFlow(helloWorldFlowConfig); List<FlowConfiguration<?>> flowConfigs = Lists.newArrayList(helloWorldFlowConfig); ReflectionTestUtils.setField(underTest, "flowConfigs", flowConfigs); underTest.restartFlow(FLOW_ID); verify(flowChainHandler, times(1)).restoreFlowChain(FLOW_CHAIN_ID); verify(flowLogService, times(1)).terminate(STACK_ID, FLOW_ID); verify(defaultRestartAction, never()).restart(any(), any(), any(), any()); }
Example #4
Source File: VirtualFileSystem.java From drftpd with GNU General Public License v2.0 | 6 votes |
/** * Write the Inode data to the disk. * * @param inode */ protected void writeInode(VirtualFileSystemInode inode) { String fullPath = getRealPath(inode.getPath()); if (inode instanceof VirtualFileSystemRoot) { new File(fileSystemPath).mkdirs(); fullPath = fullPath + separator + dirName; } else if (inode.isDirectory()) { new File(fullPath).mkdirs(); fullPath = fullPath + separator + dirName; } else { new File(getRealPath(inode.getParent().getPath())).mkdirs(); } Map<String, Object> params = new HashMap<>(); params.put(JsonWriter.PRETTY_PRINT, true); try (OutputStream out = new SafeFileOutputStream(fullPath); JsonWriter writer = new JsonWriter(out, params)) { writer.write(inode); logger.debug("Wrote fullPath {}", fullPath); } catch (IOException | JsonIoException e) { logger.error("Unable to write {} to disk", fullPath, e); } }
Example #5
Source File: FlowLogDBServiceTest.java From cloudbreak with Apache License 2.0 | 6 votes |
@Test public void updateLastFlowLogPayload() { FlowLog flowLog = new FlowLog(); flowLog.setId(ID); Payload payload = mock(Selectable.class); Map<Object, Object> variables = Map.of("repeated", 2); underTest.updateLastFlowLogPayload(flowLog, payload, variables); ArgumentCaptor<FlowLog> flowLogCaptor = ArgumentCaptor.forClass(FlowLog.class); verify(flowLogRepository, times(1)).save(flowLogCaptor.capture()); FlowLog savedFlowLog = flowLogCaptor.getValue(); assertEquals(flowLog.getId(), savedFlowLog.getId()); String payloadJson = JsonWriter.objectToJson(payload, Map.of()); String variablesJson = JsonWriter.objectToJson(variables, Map.of()); assertEquals(payloadJson, savedFlowLog.getPayload()); assertEquals(variablesJson, savedFlowLog.getVariables()); }
Example #6
Source File: VirtualFileSystem.java From drftpd with GNU General Public License v2.0 | 6 votes |
/** * Write the Inode data to the disk. * * @param inode */ protected void writeInode(VirtualFileSystemInode inode) { String fullPath = getRealPath(inode.getPath()); if (inode instanceof VirtualFileSystemRoot) { new File(fileSystemPath).mkdirs(); fullPath = fullPath + separator + dirName; } else if (inode.isDirectory()) { new File(fullPath).mkdirs(); fullPath = fullPath + separator + dirName; } else { new File(getRealPath(inode.getParent().getPath())).mkdirs(); } Map<String, Object> params = new HashMap<>(); params.put(JsonWriter.PRETTY_PRINT, true); try (OutputStream out = new SafeFileOutputStream(fullPath); JsonWriter writer = new JsonWriter(out, params)) { writer.write(inode); logger.debug("Wrote fullPath {}", fullPath); } catch (IOException | JsonIoException e) { logger.error("Unable to write {} to disk", fullPath, e); } }
Example #7
Source File: ClientsJsonProvider.java From java-json-benchmark with MIT License | 6 votes |
public ClientsJsonProvider() { jsonioStreamOptions.put(JsonReader.USE_MAPS, true); jsonioStreamOptions.put(JsonWriter.TYPE, false); // set johnson JsonReader (default is `JsonProvider.provider()`) javax.json.spi.JsonProvider johnzonProvider = new JsonProviderImpl(); johnzon = new org.apache.johnzon.mapper.MapperBuilder() .setReaderFactory(johnzonProvider.createReaderFactory(Collections.emptyMap())) .setGeneratorFactory(johnzonProvider.createGeneratorFactory(Collections.emptyMap())) .setAccessModeName("field") // default is "strict-method" which doesn't work nicely with public attributes .build(); TypeConverterManager joddTypeConverterManager = TypeConverterManager.get(); joddTypeConverterManager.register(UUID.class, (TypeConverter<UUID>) value -> UUID.fromString((String)value)); joddTypeConverterManager.register(LocalDate.class, (TypeConverter<LocalDate>) value -> LocalDate.parse((String)value)); joddTypeConverterManager.register(OffsetDateTime.class, (TypeConverter<OffsetDateTime>) value -> OffsetDateTime.parse((String)value)); }
Example #8
Source File: TSplunkEventCollectorWriter.java From components with Apache License 2.0 | 5 votes |
public TSplunkEventCollectorWriter(TSplunkEventCollectorWriteOperation writeOperation, String serverUrl, String token, int eventsBatchSize, Schema designSchema, RuntimeContainer container) { this.writeOperation = writeOperation; this.fullRequestUrl = serverUrl.endsWith("/") ? (serverUrl + servicesSuffix) : (serverUrl + "/" + servicesSuffix); this.token = token; this.eventsBatchSize = eventsBatchSize; setSchema(designSchema); args.put(JsonWriter.TYPE, false); }
Example #9
Source File: FlowLogDBService.java From cloudbreak with Apache License 2.0 | 5 votes |
public String getSerializedString(Object object) { String objectAsString; try { objectAsString = JsonWriter.objectToJson(object, writeOptions); } catch (Exception e) { LOGGER.debug("Somehow can not serialize object to string, try another method..", e); objectAsString = JsonUtil.writeValueAsStringSilent(object); } return objectAsString; }
Example #10
Source File: NukeBeans.java From drftpd with GNU General Public License v2.0 | 5 votes |
/** * Serializes the TreeMap. * * @throws IOException */ public void commit() throws IOException { Map<String, Object> params = new HashMap<>(); params.put(JsonWriter.PRETTY_PRINT, true); try (OutputStream out = new SafeFileOutputStream(_nukebeansPath + VirtualFileSystem.separator + "nukebeans.json"); JsonWriter writer = new JsonWriter(out, params)) { writer.write(_nukes); } catch (IOException | JsonIoException e) { throw new IOException(e.getMessage()); } }
Example #11
Source File: BeanGroup.java From drftpd with GNU General Public License v2.0 | 5 votes |
public void writeToDisk() throws IOException { if (_purged) return; Map<String, Object> params = new HashMap<>(); params.put(JsonWriter.PRETTY_PRINT, true); try (OutputStream out = new SafeFileOutputStream(_um.getGroupFile(getName())); JsonWriter writer = new JsonWriter(out, params)) { writer.write(this); logger.debug("Wrote groupfile for {}", this.getName()); } catch (IOException | JsonIoException e) { throw new IOException("Unable to write " + _um.getGroupFile(getName()) + " to disk", e); } }
Example #12
Source File: BeanUser.java From drftpd with GNU General Public License v2.0 | 5 votes |
public void writeToDisk() throws IOException { if (_purged) return; Map<String, Object> params = new HashMap<>(); params.put(JsonWriter.PRETTY_PRINT, true); try (OutputStream out = new SafeFileOutputStream(_um.getUserFile(getName())); JsonWriter writer = new JsonWriter(out, params)) { writer.write(this); logger.debug("Wrote userfile for {}", this.getName()); } catch (IOException | JsonIoException e) { throw new IOException("Unable to write " + _um.getUserFile(getName()) + " to disk", e); } }
Example #13
Source File: RemoteSlave.java From drftpd with GNU General Public License v2.0 | 5 votes |
public void writeToDisk() { Map<String, Object> params = new HashMap<>(); params.put(JsonWriter.PRETTY_PRINT, true); try (OutputStream out = new SafeFileOutputStream( getGlobalContext().getSlaveManager().getSlaveFile(this.getName())); JsonWriter writer = new JsonWriter(out, params)) { writer.write(this); logger.debug("Wrote slavefile for {}", this.getName()); } catch (IOException | JsonIoException e) { throw new RuntimeException("Error writing slavefile for " + this.getName() + ": " + e.getMessage(), e); } }
Example #14
Source File: BeanUser.java From drftpd with GNU General Public License v2.0 | 5 votes |
public void writeToDisk() throws IOException { if (_purged) return; Map<String, Object> params = new HashMap<>(); params.put(JsonWriter.PRETTY_PRINT, true); try (OutputStream out = new SafeFileOutputStream(_um.getUserFile(getName())); JsonWriter writer = new JsonWriter(out, params)) { writer.write(this); logger.debug("Wrote userfile for {}", this.getName()); } catch (IOException | JsonIoException e) { throw new IOException("Unable to write " + _um.getUserFile(getName()) + " to disk", e); } }
Example #15
Source File: TSplunkEventCollectorWriter.java From components with Apache License 2.0 | 5 votes |
public HttpPost createRequest(List<SplunkJSONEvent> events) throws UnsupportedEncodingException { HttpPost request = new HttpPost(fullRequestUrl); request.addHeader("Authorization", "Splunk " + token); StringBuffer requestString = new StringBuffer(); for (SplunkJSONEvent event : events) { requestString.append(JsonWriter.objectToJson(event, args)); } request.setEntity(new StringEntity(requestString.toString())); return request; }
Example #16
Source File: StatsResource.java From lumongo with Apache License 2.0 | 5 votes |
@GET @Produces({ MediaType.APPLICATION_JSON + ";charset=utf-8" }) public Response get(@Context Response response, @QueryParam(LumongoConstants.PRETTY) boolean pretty) { try { Document mongoDocument = new Document(); mongoDocument.put("indexBlockSize", indexManager.getClusterConfig().getIndexBlockSize()); mongoDocument.put("maxIndexBlockCount", indexManager.getClusterConfig().getMaxIndexBlocks()); mongoDocument.put("currentIndexBlockCount", MongoFile.getCacheSize()); Runtime runtime = Runtime.getRuntime(); mongoDocument.put("jvmUsedMemoryMB", (runtime.totalMemory() - runtime.freeMemory()) / MB); mongoDocument.put("jvmFreeMemoryMB", runtime.freeMemory() / MB); mongoDocument.put("jvmTotalMemoryMB", runtime.totalMemory() / MB); mongoDocument.put("jvmMaxMemoryMB", runtime.maxMemory() / MB); String docString = JSONSerializers.getStrict().serialize(mongoDocument); if (pretty) { docString = JsonWriter.formatJson(docString); } return Response.status(LumongoConstants.SUCCESS).entity(docString).build(); } catch (Exception e) { return Response.status(LumongoConstants.INTERNAL_ERROR).entity("Failed to get cluster membership: " + e.getMessage()).build(); } }
Example #17
Source File: FieldsResource.java From lumongo with Apache License 2.0 | 5 votes |
@GET @Produces({ MediaType.APPLICATION_JSON + ";charset=utf-8" }) public Response get(@Context Response response, @QueryParam(LumongoConstants.INDEX) final String indexName, @QueryParam(LumongoConstants.PRETTY) boolean pretty) { if (indexName != null) { Lumongo.GetFieldNamesRequest fieldNamesRequest = Lumongo.GetFieldNamesRequest.newBuilder().setIndexName(indexName).build(); Lumongo.GetFieldNamesResponse fieldNamesResponse; try { fieldNamesResponse = indexManager.getFieldNames(fieldNamesRequest); Document mongoDocument = new Document(); mongoDocument.put("index", indexName); mongoDocument.put("fields", fieldNamesResponse.getFieldNameList()); String docString = JSONSerializers.getStrict().serialize(mongoDocument); if (pretty) { docString = JsonWriter.formatJson(docString); } return Response.status(LumongoConstants.SUCCESS).entity(docString).build(); } catch (Exception e) { return Response.status(LumongoConstants.INTERNAL_ERROR).entity("Failed to fetch fields for index <" + indexName + ">: " + e.getMessage()) .build(); } } else { return Response.status(LumongoConstants.INTERNAL_ERROR).entity("No index defined").build(); } }
Example #18
Source File: IndexResource.java From lumongo with Apache License 2.0 | 5 votes |
@GET @Produces({ MediaType.APPLICATION_JSON + ";charset=utf-8" }) public Response get(@Context Response response, @QueryParam(LumongoConstants.INDEX) String index, @QueryParam(LumongoConstants.PRETTY) boolean pretty) { try { StringBuilder responseBuilder = new StringBuilder(); IndexConfig indexConfig = indexManager.getIndexConfig(index); responseBuilder.append("{"); responseBuilder.append("\"indexName\": "); responseBuilder.append("\""); responseBuilder.append(indexConfig.getIndexName()); responseBuilder.append("\""); responseBuilder.append(","); responseBuilder.append("\"numberOfSegments\": "); responseBuilder.append(indexConfig.getNumberOfSegments()); responseBuilder.append(","); responseBuilder.append("\"indexSettings\": "); JsonFormat.Printer printer = JsonFormat.printer(); responseBuilder.append(printer.print(indexConfig.getIndexSettings())); responseBuilder.append("}"); String docString = responseBuilder.toString(); if (pretty) { docString = JsonWriter.formatJson(docString); } return Response.status(LumongoConstants.SUCCESS).entity(docString).build(); } catch (Exception e) { return Response.status(LumongoConstants.INTERNAL_ERROR).entity("Failed to get index names: " + e.getMessage()).build(); } }
Example #19
Source File: RemoteSlave.java From drftpd with GNU General Public License v2.0 | 5 votes |
public void writeToDisk() { Map<String, Object> params = new HashMap<>(); params.put(JsonWriter.PRETTY_PRINT, true); try (OutputStream out = new SafeFileOutputStream( getGlobalContext().getSlaveManager().getSlaveFile(this.getName())); JsonWriter writer = new JsonWriter(out, params)) { writer.write(this); logger.debug("Wrote slavefile for {}", this.getName()); } catch (IOException | JsonIoException e) { throw new RuntimeException("Error writing slavefile for " + this.getName() + ": " + e.getMessage(), e); } }
Example #20
Source File: BeanGroup.java From drftpd with GNU General Public License v2.0 | 5 votes |
public void writeToDisk() throws IOException { if (_purged) return; Map<String, Object> params = new HashMap<>(); params.put(JsonWriter.PRETTY_PRINT, true); try (OutputStream out = new SafeFileOutputStream(_um.getGroupFile(getName())); JsonWriter writer = new JsonWriter(out, params)) { writer.write(this); logger.debug("Wrote groupfile for {}", this.getName()); } catch (IOException | JsonIoException e) { throw new IOException("Unable to write " + _um.getGroupFile(getName()) + " to disk", e); } }
Example #21
Source File: NukeBeans.java From drftpd with GNU General Public License v2.0 | 5 votes |
/** * Serializes the TreeMap. * * @throws IOException */ public void commit() throws IOException { Map<String, Object> params = new HashMap<>(); params.put(JsonWriter.PRETTY_PRINT, true); try (OutputStream out = new SafeFileOutputStream(_nukebeansPath + VirtualFileSystem.separator + "nukebeans.json"); JsonWriter writer = new JsonWriter(out, params)) { writer.write(_nukes); } catch (IOException | JsonIoException e) { throw new IOException(e.getMessage()); } }
Example #22
Source File: UsersJsonProvider.java From java-json-benchmark with MIT License | 5 votes |
public UsersJsonProvider() { jacksonAfterburner.registerModule(new AfterburnerModule()); jsonioStreamOptions.put(JsonReader.USE_MAPS, true); jsonioStreamOptions.put(JsonWriter.TYPE, false); // set johnson JsonReader (default is `JsonProvider.provider()`) javax.json.spi.JsonProvider johnzonProvider = new JsonProviderImpl(); johnzon = new org.apache.johnzon.mapper.MapperBuilder() .setReaderFactory(johnzonProvider.createReaderFactory(Collections.emptyMap())) .setGeneratorFactory(johnzonProvider.createGeneratorFactory(Collections.emptyMap())) .setAccessModeName("field") // default is "strict-method" which doesn't work nicely with public attributes .build(); }
Example #23
Source File: FlowLogDBService.java From cloudbreak with Apache License 2.0 | 5 votes |
public void updateLastFlowLogPayload(FlowLog lastFlowLog, Payload payload, Map<Object, Object> variables) { String payloadJson = JsonWriter.objectToJson(payload, writeOptions); String variablesJson = JsonWriter.objectToJson(variables, writeOptions); Optional.ofNullable(lastFlowLog) .ifPresent(flowLog -> { flowLog.setPayload(payloadJson); flowLog.setVariables(variablesJson); flowLogRepository.save(flowLog); }); }
Example #24
Source File: JsonIoConfig.java From cloudbreak with Apache License 2.0 | 5 votes |
@Bean(name = "JsonWriterOptions") public Map<String, Object> getCustomWriteOptions() { Map<Class<?>, JsonClassWriterBase> customWriters = new HashMap<>(); customWriters.put(Exception.class, new NonPrimitiveFormJsonWriter() { @Override public void write(Object o, boolean showType, Writer output) throws IOException { output.write("\"detailMessage\":"); JsonWriter.writeJsonUtf8String(((Throwable) o).getMessage(), output); } }); return Collections.singletonMap(CUSTOM_WRITER_MAP, customWriters); }
Example #25
Source File: Flow2HandlerTest.java From cloudbreak with Apache License 2.0 | 5 votes |
@Test public void testRestartFlow() throws TransactionExecutionException { ReflectionTestUtils.setField(underTest, "flowChainHandler", flowChainHandler); FlowLog flowLog = createFlowLog(FLOW_CHAIN_ID); Payload payload = new TestPayload(STACK_ID); flowLog.setPayload(JsonWriter.objectToJson(payload)); when(applicationFlowInformation.getRestartableFlows()).thenReturn(List.of(HelloWorldFlowConfig.class)); when(flowLogService.findFirstByFlowIdOrderByCreatedDesc(FLOW_ID)).thenReturn(Optional.of(flowLog)); HelloWorldFlowConfig helloWorldFlowConfig = new HelloWorldFlowConfig(); ReflectionTestUtils.setField(helloWorldFlowConfig, "defaultRestartAction", defaultRestartAction); setUpFlowConfigCreateFlow(helloWorldFlowConfig); List<FlowConfiguration<?>> flowConfigs = Lists.newArrayList(helloWorldFlowConfig); ReflectionTestUtils.setField(underTest, "flowConfigs", flowConfigs); underTest.restartFlow(FLOW_ID); ArgumentCaptor<Payload> payloadCaptor = ArgumentCaptor.forClass(Payload.class); ArgumentCaptor<FlowParameters> flowParamsCaptor = ArgumentCaptor.forClass(FlowParameters.class); verify(flowChainHandler, times(1)).restoreFlowChain(FLOW_CHAIN_ID); verify(flowLogService, never()).terminate(STACK_ID, FLOW_ID); verify(defaultRestartAction, times(1)).restart(flowParamsCaptor.capture(), eq(FLOW_CHAIN_ID), eq(NEXT_EVENT), payloadCaptor.capture()); Payload captorValue = payloadCaptor.getValue(); assertEquals(STACK_ID, captorValue.getResourceId()); FlowParameters flowParameters = flowParamsCaptor.getValue(); assertEquals(FLOW_ID, flowParameters.getFlowId()); assertEquals(FLOW_TRIGGER_USERCRN, flowParameters.getFlowTriggerUserCrn()); }
Example #26
Source File: Flow2HandlerTest.java From cloudbreak with Apache License 2.0 | 5 votes |
private FlowLog createFlowLog(String flowChainId) { FlowLog flowLog = new FlowLog(STACK_ID, FLOW_ID, "START_STATE", true, StateStatus.SUCCESSFUL); flowLog.setFlowType(HelloWorldFlowConfig.class); flowLog.setVariables(JsonWriter.objectToJson(new HashMap<>())); flowLog.setFlowChainId(flowChainId); flowLog.setNextEvent(NEXT_EVENT); flowLog.setFlowTriggerUserCrn(FLOW_TRIGGER_USERCRN); return flowLog; }
Example #27
Source File: TerminationTriggerServiceTest.java From cloudbreak with Apache License 2.0 | 5 votes |
private FlowLog getTerminationFlowLog(boolean forced) { FlowLog flowLog = new FlowLog(); flowLog.setFlowType(StackTerminationFlowConfig.class); flowLog.setCurrentState("INIT_STATE"); TerminationEvent event = new TerminationEvent("selector", 1L, forced); flowLog.setPayload(JsonWriter.objectToJson(event)); flowLog.setPayloadType(TerminationEvent.class); return flowLog; }
Example #28
Source File: TestGraphComparator.java From java-util with Apache License 2.0 | 4 votes |
private Object clone(Object source) throws Exception { String json = JsonWriter.objectToJson(source); return JsonReader.jsonToJava(json); }
Example #29
Source File: FlowLogDBService.java From cloudbreak with Apache License 2.0 | 4 votes |
public void saveChain(String flowChainId, String parentFlowChainId, Queue<Selectable> chain, String flowTriggerUserCrn) { String chainJson = JsonWriter.objectToJson(chain); FlowChainLog chainLog = new FlowChainLog(flowChainId, parentFlowChainId, chainJson, flowTriggerUserCrn); flowChainLogService.save(chainLog); }
Example #30
Source File: FetchResource.java From lumongo with Apache License 2.0 | 4 votes |
@GET @Produces({ MediaType.APPLICATION_JSON + ";charset=utf-8" }) public Response get(@Context Response response, @QueryParam(LumongoConstants.ID) final String uniqueId, @QueryParam(LumongoConstants.INDEX) final String indexName, @QueryParam(LumongoConstants.PRETTY) boolean pretty) { Lumongo.FetchRequest.Builder fetchRequest = Lumongo.FetchRequest.newBuilder(); fetchRequest.setIndexName(indexName); fetchRequest.setUniqueId(uniqueId); Lumongo.FetchResponse fetchResponse; try { fetchResponse = indexManager.fetch(fetchRequest.build()); if (fetchResponse.hasResultDocument()) { Document document = ResultHelper.getDocumentFromResultDocument(fetchResponse.getResultDocument()); String docString; if (pretty) { docString = JSONSerializers.getLegacy().serialize(document); } else { docString = JSONSerializers.getStrict().serialize(document); } if (pretty) { docString = JsonWriter.formatJson(docString); } return Response.status(LumongoConstants.SUCCESS).entity(docString).build(); } else { return Response.status(LumongoConstants.NOT_FOUND).entity("Failed to fetch uniqueId <" + uniqueId + "> for index <" + indexName + ">").build(); } } catch (Exception e) { return Response.status(LumongoConstants.INTERNAL_ERROR) .entity("Failed to fetch uniqueId <" + uniqueId + "> for index <" + indexName + ">: " + e.getMessage()).build(); } }