@OperationMethod public BusinessAdapter run(BusinessAdapter input) throws ClassNotFoundException { DocumentModel document = input.getDocument(); session.saveDocument(document); return input; }
@OperationMethod public BusinessAdapter run(BusinessAdapter input) throws ClassNotFoundException { DocumentModel document = session.getDocument(new IdRef(input.getId())); return document.getAdapter(input.getClass()); } }
/** * When the object codec is called the stream is positioned on the first value. For inlined objects this is the * first value after the "entity-type" property. For non inlined objects this will be the object itself (i.e. * '{' or '[') * * @param jp * @return * @throws IOException */ @Override public BusinessAdapter read(JsonParser jp, CoreSession session) throws IOException { if (jp.getCodec() == null) { jp.setCodec(new ObjectMapper()); } BusinessAdapter fromBa = jp.readValueAs(type); DocumentModel doc = fromBa.getId() != null ? session.getDocument(new IdRef(fromBa.getId())) : DocumentModelFactory.createDocumentModel(fromBa.getType()); BusinessAdapter ba = doc.getAdapter(fromBa.getClass()); // And finally copy the fields sets from the adapter for (String schema : fromBa.getDocument().getSchemas()) { DataModel dataModel = ba.getDocument().getDataModel(schema); DataModel fromDataModel = fromBa.getDocument().getDataModel(schema); for (String field : fromDataModel.getDirtyFields()) { dataModel.setData(field, fromDataModel.getData(field)); } } return ba; } }
@OperationMethod public BusinessAdapter run(BusinessAdapter input) { DocumentModel document = input.getDocument(); // TODO the code intends to copy to a new document with parentPath+name but it's buggy and does not do that // TODO currently we just create a placeless document with an random name // TODO use createDocumentModel instead of document to fix // createDocumentModel.copyContent(document); document = session.createDocument(document); return document.getAdapter(input.getClass()); }
@PUT @Path("{adapterName}") @Consumes(MediaType.APPLICATION_JSON) public Object doPostAdapter(@PathParam("adapterName") String adapterName, BusinessAdapter input) { ctx.getCoreSession().saveDocument(input.getDocument()); ctx.getCoreSession().save(); return new DefaultJsonAdapter(input); }
@POST @Path("{adapterName}/{docName}") public Object doPutAdapter(@PathParam("adapterName") String adapterName, @PathParam("docName") String docName, BusinessAdapter input) { DocumentModel document = input.getDocument(); DocumentObject dobj = (DocumentObject) getTarget(); DocumentModel parentDoc = dobj.getDocument(); document.setPathInfo(parentDoc.getPathAsString(), docName); CoreSession session = ctx.getCoreSession(); document = session.createDocument(document); session.save(); BusinessAdapter adapter = document.getAdapter(input.getClass()); return new DefaultJsonAdapter(adapter); }