Search in sources :

Example 1 with JSONBException

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;
}
Also used : SQLException(java.sql.SQLException) JSONBException(dk.dbc.commons.jsonb.JSONBException) PGobject(org.postgresql.util.PGobject)

Example 2 with JSONBException

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;
}
Also used : SQLException(java.sql.SQLException) JSONBException(dk.dbc.commons.jsonb.JSONBException) PGobject(org.postgresql.util.PGobject)

Example 3 with JSONBException

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));
    }
}
Also used : InvalidMessageException(dk.dbc.dataio.commons.types.exceptions.InvalidMessageException) JobStoreException(dk.dbc.dataio.jobstore.types.JobStoreException) Chunk(dk.dbc.dataio.commons.types.Chunk) JSONBException(dk.dbc.commons.jsonb.JSONBException) Stopwatch(dk.dbc.dataio.commons.types.interceptor.Stopwatch)

Example 4 with JSONBException

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), "");
}
Also used : FlowStoreError(dk.dbc.dataio.commons.types.FlowStoreError) FlowBinderContentMatch(dk.dbc.dataio.flowstore.model.FlowBinderContentMatch) FlowBinderContent(dk.dbc.dataio.commons.types.FlowBinderContent) JSONBException(dk.dbc.commons.jsonb.JSONBException) FlowBinder(dk.dbc.dataio.flowstore.entity.FlowBinder)

Example 5 with JSONBException

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();
    }
}
Also used : Query(javax.persistence.Query) JSONBException(dk.dbc.commons.jsonb.JSONBException) HarvesterConfig(dk.dbc.dataio.flowstore.entity.HarvesterConfig) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

JSONBException (dk.dbc.commons.jsonb.JSONBException)65 Path (javax.ws.rs.Path)17 SQLException (java.sql.SQLException)16 Produces (javax.ws.rs.Produces)16 Consumes (javax.ws.rs.Consumes)14 POST (javax.ws.rs.POST)14 PGobject (org.postgresql.util.PGobject)14 Stopwatch (dk.dbc.dataio.commons.types.interceptor.Stopwatch)13 JobError (dk.dbc.dataio.jobstore.types.JobError)10 Chunk (dk.dbc.dataio.commons.types.Chunk)8 JobStoreException (dk.dbc.dataio.jobstore.types.JobStoreException)8 JobInfoSnapshot (dk.dbc.dataio.jobstore.types.JobInfoSnapshot)7 IOException (java.io.IOException)7 AddiRecord (dk.dbc.commons.addi.AddiRecord)6 AddiReader (dk.dbc.commons.addi.AddiReader)5 JSONBContext (dk.dbc.commons.jsonb.JSONBContext)5 AddiMetaData (dk.dbc.dataio.commons.types.AddiMetaData)5 ChunkItem (dk.dbc.dataio.commons.types.ChunkItem)5 InvalidMessageException (dk.dbc.dataio.commons.types.exceptions.InvalidMessageException)4 JobInputStream (dk.dbc.dataio.jobstore.types.JobInputStream)4