Skip to content

Commit

Permalink
NXP-11260: fix document model adapter initialization with the related…
Browse files Browse the repository at this point in the history
… proper document type - update test with document type Note
  • Loading branch information
Vladimir Pasquier committed Jun 21, 2013
1 parent 144b5d1 commit 5b76441
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,22 @@ public abstract class BusinessAdapter {

private static final Log log = LogFactory.getLog(BusinessAdapter.class);

protected transient DocumentModel doc;

@JsonProperty("id")
protected String id;
protected final String id;

public BusinessAdapter() {
this.doc = DocumentModelFactory.createDocumentModel("File");
@JsonProperty("type")
protected final String type;

protected transient DocumentModel doc;

public BusinessAdapter(String type) {
this.type = type;
this.doc = DocumentModelFactory.createDocumentModel(type);
this.id = doc.getId();
}

public BusinessAdapter(DocumentModel document) {
this.type = document.getType();
this.doc = document;
this.id = doc.getId();
}
Expand All @@ -67,4 +72,8 @@ public String getId() {
return doc.getId();
}

public String getType() {
return doc.getType();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -783,23 +783,24 @@ public void testAutomationDocumentService() throws Exception {
@Test
public void testAutomationBusinessObjects() throws Exception {
// Test for pojo <-> adapter automation creation
BusinessBean file = new BusinessBean("File", "File description");
BusinessBean note = new BusinessBean("Note", "File description",
"Note Content", "Note");
BusinessService businessService = session.getAdapter(BusinessService.class);
assertNotNull(businessService);

// adding BusinessBean marshaller
JsonMarshalling.addMarshaller(PojoMarshaller.forClass(file.getClass()));
JsonMarshalling.addMarshaller(PojoMarshaller.forClass(note.getClass()));

// This request can be done directly with
// Operation.BusinessCreateOperation ->
// session.newRequest("Operation.BusinessCreateOperation").setInput(o).set("name",
// name).set("type", type).set("parentPath",parentPath).execute();
file = (BusinessBean) businessService.create(file, file.getTitle(),
"File", "/");
assertNotNull(file);
note = (BusinessBean) businessService.create(note, note.getTitle(),
note.getType(), "/");
assertNotNull(note);
// Test for pojo <-> adapter automation update
file.setTitle("Update");
file = (BusinessBean) businessService.update(file, file.getId());
assertEquals("Update", file.getTitle());
note.setTitle("Update");
note = (BusinessBean) businessService.update(note, note.getId());
assertEquals("Update", note.getTitle());
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
/*
* Copyright (c) 2006-2013 Nuxeo SA (http://nuxeo.com/) and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Vladimir Pasquier <vpasquier@nuxeo.com>
*/
package org.nuxeo.ecm.automation.server.test.business.adapter;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonProperty;
import org.nuxeo.ecm.automation.core.operations.business.adapter.BusinessAdapter;
import org.nuxeo.ecm.core.api.ClientException;
import org.nuxeo.ecm.core.api.DocumentModel;
Expand All @@ -13,8 +26,14 @@ public class BusinessBeanAdapter extends BusinessAdapter {

private static final Log log = LogFactory.getLog(BusinessBeanAdapter.class);

public BusinessBeanAdapter() {
super();
/**
* This constructor is used by Jackson to initialize the adapter with the
* proper document type
*/
@JsonCreator
public BusinessBeanAdapter(@JsonProperty("type")
String type) {
super(type);
}

public BusinessBeanAdapter(DocumentModel documentModel) {
Expand Down Expand Up @@ -55,4 +74,21 @@ public void setDescription(String value) {
}
}

public String getNote() {
try {
return (String) doc.getPropertyValue("note:note");
} catch (ClientException e) {
log.error("cannot get note property", e);
}
return null;
}

public void setNote(String value) {
try {
doc.setPropertyValue("note:note", value);
} catch (ClientException e) {
log.error("cannot get note property", e);
}
}

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
* Copyright (c) 2006-2013 Nuxeo SA (http://nuxeo.com/) and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Vladimir Pasquier <vpasquier@nuxeo.com>
*/
package org.nuxeo.ecm.automation.server.test.business.adapter;

import org.nuxeo.ecm.core.api.DocumentModel;
Expand All @@ -7,7 +18,7 @@ public class BusinessBeanAdapterFactory implements DocumentAdapterFactory {

@Override
public Object getAdapter(DocumentModel doc, Class<?> itf) {
if ("File".equals(doc.getType())) {
if ("Note".equals(doc.getType())) {
return new BusinessBeanAdapter(doc);
} else {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,35 @@ public class BusinessBean {

protected String id;

protected String note;

protected String type;

public BusinessBean() {
}

public BusinessBean(String title, String description) {
public BusinessBean(String title, String description, String note,
String type) {
this.title = title;
this.description = description;
this.note = note;
this.type = type;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public String getNote() {
return note;
}

public void setNote(String note) {
this.note = note;
}

public String getTitle() {
Expand Down

0 comments on commit 5b76441

Please sign in to comment.