use of dk.dbc.commons.jsonb.JSONBException in project solr-document-store by DBCDK.
the class PgHoldingsKeysToPgConverter method convertToDatabaseColumn.
@Override
public PGobject convertToDatabaseColumn(List<Map<String, List<String>>> content) throws IllegalStateException {
final PGobject pgObject = new PGobject();
pgObject.setType("jsonb");
try {
pgObject.setValue(context.marshall(content));
} catch (SQLException | JSONBException e) {
throw new IllegalStateException(e);
}
return pgObject;
}
use of dk.dbc.commons.jsonb.JSONBException in project solr-document-store by DBCDK.
the class PgMapOfStringsToJsonConverter method convertToDatabaseColumn.
@Override
public PGobject convertToDatabaseColumn(Map<String, List<String>> content) throws IllegalStateException {
final PGobject pgObject = new PGobject();
pgObject.setType("jsonb");
try {
pgObject.setValue(context.marshall(content));
} catch (SQLException | JSONBException e) {
throw new IllegalStateException(e);
}
return pgObject;
}
use of dk.dbc.commons.jsonb.JSONBException in project dataio by DBCDK.
the class TestJobProcessorMessageConsumerBean method handleConsumedMessage.
/**
* Processes Chunk received in consumed message
*
* @param consumedMessage message to be handled
* @throws InvalidMessageException if message payload can not be unmarshalled to chunk instance
*/
@Stopwatch
public synchronized void handleConsumedMessage(ConsumedMessage consumedMessage) throws InvalidMessageException {
try {
final Chunk chunk = jsonbContext.unmarshall(consumedMessage.getMessagePayload(), Chunk.class);
LOGGER.info("Received chunk {}/{}", chunk.getJobId(), chunk.getChunkId());
confirmLegalChunkTypeOrThrow(chunk, Chunk.Type.PARTITIONED);
process(chunk);
} catch (JSONBException e) {
throw new InvalidMessageException(String.format("Message<%s> payload was not valid Chunk type %s", consumedMessage.getMessageId(), consumedMessage.getHeaderValue(JmsConstants.CHUNK_PAYLOAD_TYPE, String.class)), e);
} catch (JobStoreException e) {
throw new InvalidMessageException(String.format("Message<%s> Failed in JobStore %s", consumedMessage.getMessageId(), e.getMessage(), e));
}
}
use of dk.dbc.commons.jsonb.JSONBException in project dataio by DBCDK.
the class FlowBindersBean method getFlowBinderResolveError.
/**
* Finds specific cause of failure to resolve a flow binder
*
* @param submitterNumber submitter number
* @param requestedMatch match parameters of the resolve request
* @return error containing the appropriate error message
*/
private FlowStoreError getFlowBinderResolveError(Long submitterNumber, FlowBinderContentMatch requestedMatch) {
if (requestedMatch.getSubmitterIds() == null || requestedMatch.getSubmitterIds().isEmpty()) {
return new FlowStoreError(FlowStoreError.Code.NONEXISTING_SUBMITTER, "Intet biblioteksnummer angivet", "");
}
final FlowBinderContentMatch submitterMatch = new FlowBinderContentMatch().withSubmitterIds(requestedMatch.getSubmitterIds());
final List<FlowBinder> flowBindersMatchedBySubmitter = entityManager.createNamedQuery(FlowBinder.MATCH_FLOWBINDER_QUERY_NAME, FlowBinder.class).setParameter(1, submitterMatch.toString()).getResultList();
if (flowBindersMatchedBySubmitter.isEmpty()) {
return new FlowStoreError(FlowStoreError.Code.NONEXISTING_SUBMITTER, String.format("Biblioteksnummer %s kan ikke findes", submitterNumber), "");
}
for (FlowBinder flowBinder : flowBindersMatchedBySubmitter) {
try {
final FlowBinderContent flowBinderContent = jsonbContext.unmarshall(flowBinder.getContent(), FlowBinderContent.class);
if (flowBinderContent.getDestination().equals(requestedMatch.getDestination())) {
// but without one or more of the remaining values.
return new FlowStoreError(FlowStoreError.Code.EXISTING_SUBMITTER_EXISTING_DESTINATION_NONEXISTING_TOC, String.format("Én eller flere af de angivne værdier protokol(t): %s, format(o): %s, tegnsæt(c): %s," + "kan ikke findes i kombination med biblioteksnummer %s og baseparameter %s", requestedMatch.getPackaging(), requestedMatch.getFormat(), requestedMatch.getCharset(), submitterNumber, requestedMatch.getDestination()), "");
}
} catch (JSONBException e) {
throw new IllegalStateException(e);
}
}
// In the case of flow binder found for submitter but without the given destination.
return new FlowStoreError(FlowStoreError.Code.EXISTING_SUBMITTER_NONEXISTING_DESTINATION, String.format("Baseparameteren %s kan ikke findes i kombination med biblioteksnummer %s", requestedMatch.getDestination(), submitterNumber), "");
}
use of dk.dbc.commons.jsonb.JSONBException in project dataio by DBCDK.
the class HarvestersBean method findEnabledHarvesterConfigsByType.
/**
* Returns list of all enabled harvester configs of given type
*
* @param type type of config as class name with full path
* @return a HTTP 200 OK response with result list as JSON.
* a HTTP 500 INTERNAL SERVER ERROR response in case of general error.
*/
@GET
@Path(FlowStoreServiceConstants.HARVESTER_CONFIGS_TYPE_ENABLED)
@Produces({ MediaType.APPLICATION_JSON })
public Response findEnabledHarvesterConfigsByType(@PathParam("type") String type) {
final Query query = entityManager.createNamedQuery(HarvesterConfig.QUERY_FIND_ALL_ENABLED_OF_TYPE).setParameter(1, type);
final List<HarvesterConfig> results = query.getResultList();
try {
return Response.ok().entity(jsonbContext.marshall(results)).build();
} catch (JSONBException e) {
// Since JSONBException is mapped to BAD_REQUEST - note: this code will probably never be reached
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ServiceUtil.asJsonError(e)).build();
}
}
Aggregations