List of usage examples for com.mongodb.client.result UpdateResult wasAcknowledged
public abstract boolean wasAcknowledged();
From source file:org.seadpdt.impl.ROServicesImpl.java
License:Apache License
@GET @Path("/deprecate/{newRO}/{oldRO}") @Produces(MediaType.APPLICATION_JSON)//from w ww.j av a2 s. c o m public Response deprecateRO(@PathParam("newRO") String newRoId, @PathParam("oldRO") String oldRoId) { try { Response roObjectResponse = getROProfile(newRoId); Object context = new JSONObject(roObjectResponse.getEntity().toString()).get("@context"); addIfNeeded(context, Constants.alternateOf, Constants.alternateOfIRI); UpdateResult urContext = publicationsCollection.updateOne( new Document("Aggregation.Identifier", newRoId), new BasicDBObject("$set", new BasicDBObject("@context", JSON.parse(context.toString())))); UpdateResult urAggregation = publicationsCollection.updateOne( new Document("Aggregation.Identifier", newRoId), new BasicDBObject("$set", new BasicDBObject("Aggregation." + Constants.alternateOf, oldRoId))); if (urContext.wasAcknowledged() && urAggregation.wasAcknowledged()) { DeleteOverrideRO(oldRoId); return Response.status(ClientResponse.Status.OK).build(); } else { return Response.status(ClientResponse.Status.NOT_FOUND) .entity(new JSONObject().put("Error", "Error while deprecating RO")).build(); } } catch (org.bson.BsonInvalidOperationException e) { return Response.status(ClientResponse.Status.BAD_REQUEST) .entity(new JSONObject().put("Error", "Error while deprecating RO")).build(); } }
From source file:org.seadpdt.ROServices.java
License:Apache License
@POST @Path("/{id}/status") @Consumes(MediaType.APPLICATION_JSON)/*from w ww . ja v a 2 s .c o m*/ public Response setROStatus(@PathParam("id") String id, String state) { try { Document statusUpdateDocument = Document.parse(state); statusUpdateDocument.append("date", DateFormat.getDateTimeInstance().format(new Date(System.currentTimeMillis()))); UpdateResult ur = publicationsCollection.updateOne(new Document("Aggregation.Identifier", id), new BasicDBObject("$push", new BasicDBObject("Status", statusUpdateDocument))); if (ur.wasAcknowledged()) { return Response.status(ClientResponse.Status.OK).build(); } else { return Response.status(ClientResponse.Status.NOT_FOUND).build(); } } catch (org.bson.BsonInvalidOperationException e) { return Response.status(ClientResponse.Status.BAD_REQUEST).build(); } }
From source file:org.seadpdt.ROServices.java
License:Apache License
@GET @Path("/deprecate/{newRO}/{oldRO}") @Produces(MediaType.APPLICATION_JSON)/*w w w . ja v a 2 s. c om*/ public Response deprecateRO(@PathParam("newRO") String newRoId, @PathParam("oldRO") String oldRoId) { try { Response roObjectResponse = getROProfile(newRoId); Object context = new JSONObject(roObjectResponse.getEntity().toString()).get("@context"); addIfNeeded(context, Constants.alternateOf, Constants.alternateOfIRI); UpdateResult urContext = publicationsCollection.updateOne( new Document("Aggregation.Identifier", newRoId), new BasicDBObject("$set", new BasicDBObject("@context", JSON.parse(context.toString())))); UpdateResult urAggregation = publicationsCollection.updateOne( new Document("Aggregation.Identifier", newRoId), new BasicDBObject("$set", new BasicDBObject("Aggregation." + Constants.alternateOf, oldRoId))); if (urContext.wasAcknowledged() && urAggregation.wasAcknowledged()) { DeleteOverrideRO(oldRoId); return Response.status(ClientResponse.Status.OK).build(); } else { return Response.status(ClientResponse.Status.NOT_FOUND).build(); } } catch (org.bson.BsonInvalidOperationException e) { return Response.status(ClientResponse.Status.BAD_REQUEST).build(); } }