/** The Constant logger. */
private final static String CLASS_NAME = AccountRoleServiceTest.class.getName();
private final static Logger logger = LoggerFactory.getLogger(CLASS_NAME);
-
// Instance variables specific to this test.
/** The known resource id. */
private String knownResourceId = null;
-
/** The all resource ids created. */
private List<String> allResourceIdsCreated = new ArrayList<String>();
-
/** The acc values. */
private Hashtable<String, AccountValue> accValues = new Hashtable<String, AccountValue>();
-
/** The role values. */
private Hashtable<String, RoleValue> roleValues = new Hashtable<String, RoleValue>();
/*
@BeforeClass(alwaysRun = true)
public void seedData() {
String userId = "acc-role-user1";
- String accId = createAccount(userId, "acc-role-test@cspace.org");
+ String accId = createAccount(userId, "acc-role-user1-test@cspace.org");
AccountValue ava = new AccountValue();
ava.setScreenName(userId);
ava.setUserId(userId);
accValues.put(ava.getScreenName(), ava);
String userId2 = "acc-role-user2";
- String coAccId = createAccount(userId2, "acc-role-test@cspace.org");
+ String coAccId = createAccount(userId2, "acc-role-user2-test@cspace.org");
AccountValue avc = new AccountValue();
avc.setScreenName(userId2);
avc.setUserId(userId2);
avc.setAccountId(coAccId);
accValues.put(avc.getScreenName(), avc);
- String ri = "acc-role-user3";
- String iAccId = createAccount(ri, "acc-role-test@cspace.org");
- AccountValue avi = new AccountValue();
- avi.setScreenName(ri);
- avi.setUserId(ri);
- avi.setAccountId(iAccId);
- accValues.put(avi.getScreenName(), avi);
-
String rn1 = "ROLE_CO1";
String r1RoleId = createRole(rn1);
RoleValue rv1 = new RoleValue();
*/
@Override
protected CollectionSpaceClient getClientInstance() {
- return new AccountRoleClient();
+ return new AccountRoleClient();
}
-
+
/* (non-Javadoc)
* @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
*/
@Override
- protected AbstractCommonList getAbstractCommonList(
- ClientResponse<AbstractCommonList> response) {
- //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
- throw new UnsupportedOperationException();
+ protected AbstractCommonList getAbstractCommonList(
+ ClientResponse<AbstractCommonList> response) {
+ //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
+ throw new UnsupportedOperationException();
}
-
- /* (non-Javadoc)
- * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String)
- */
- @Test(dataProvider = "testName")
- @Override
+
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String)
+ */
+ @Test(dataProvider = "testName")
+ @Override
public void readPaginatedList(String testName) throws Exception {
- //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
- }
-
+ //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
+ }
+
// ---------------------------------------------------------------
// CRUD tests : CREATE tests
// ---------------------------------------------------------------
AccountRoleClient client = new AccountRoleClient();
ClientResponse<Response> res = client.create(pv.getAccountId(), accRole);
try {
- int statusCode = res.getStatus();
-
- if (logger.isDebugEnabled()) {
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-
- // Store the ID returned from this create operation
- // for additional tests below.
- //this is is not important in case of this relationship
- knownResourceId = extractId(res);
- if (logger.isDebugEnabled()) {
- logger.debug(testName + ": knownResourceId=" + knownResourceId);
- }
+ int statusCode = res.getStatus();
+
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ // Store the ID returned from this create operation
+ // for additional tests below.
+ //this is is not important in case of this relationship
+ knownResourceId = extractId(res);
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": knownResourceId=" + knownResourceId);
+ }
} finally {
- res.releaseConnection();
+ res.releaseConnection();
}
}
dependsOnMethods = {"create"})
@Override
public void createList(String testName) throws Exception {
- //FIXME: Should this test really be empty? If so, please comment accordingly.
+ //FIXME: Should this test really be empty? If so, please comment accordingly.
}
// Failure outcomes
*/
@Override
public void createWithEmptyEntityBody(String testName) throws Exception {
- //FIXME: Should this test really be empty? If so, please comment accordingly.
+ //FIXME: Should this test really be empty? If so, please comment accordingly.
}
/* (non-Javadoc)
*/
@Override
public void createWithMalformedXml(String testName) throws Exception {
- //FIXME: Should this test really be empty? If so, please comment accordingly.
+ //FIXME: Should this test really be empty? If so, please comment accordingly.
}
/* (non-Javadoc)
*/
@Override
public void createWithWrongXmlSchema(String testName) throws Exception {
- //FIXME: Should this test really be empty? If so, please comment accordingly.
+ //FIXME: Should this test really be empty? If so, please comment accordingly.
}
// ---------------------------------------------------------------
if (logger.isDebugEnabled()) {
testBanner(testName, CLASS_NAME);
}
-
+
// Perform setup.
setupRead();
accValues.get("acc-role-user1").getAccountId(), "123");
int statusCode = res.getStatus();
try {
- // Check the status code of the response: does it match
- // the expected response(s)?
- if (logger.isDebugEnabled()) {
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-
- AccountRole output = (AccountRole) res.getEntity();
- Assert.assertNotNull(output);
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ AccountRole output = (AccountRole) res.getEntity();
+ Assert.assertNotNull(output);
} finally {
- res.releaseConnection();
+ res.releaseConnection();
}
}
if (logger.isDebugEnabled()) {
testBanner(testName, CLASS_NAME);
}
-
+
// Perform setup.
setupReadNonExistent();
ClientResponse<AccountRole> res = client.read(this.NON_EXISTENT_ID, "123");
int statusCode = res.getStatus();
try {
- // Check the status code of the response: does it match
- // the expected response(s)?
- if (logger.isDebugEnabled()) {
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
} finally {
- res.releaseConnection();
+ res.releaseConnection();
+ }
+ }
+
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ dependsOnMethods = {"create"})
+ public void readNoRelationship(String testName) throws Exception {
+
+ if (logger.isDebugEnabled()) {
+ testBanner(testName, CLASS_NAME);
+ }
+
+ // Perform setup.
+ setupRead();
+
+ // Submit the request to the service and store the response.
+ AccountRoleClient client = new AccountRoleClient();
+ ClientResponse<AccountRole> res = client.read(
+ accValues.get("acc-role-user2").getAccountId(), "123");
+ int statusCode = res.getStatus();
+ try {
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
+ AccountRole output = (AccountRole) res.getEntity();
+
+ String sOutput = objectAsXmlString(output, AccountRole.class);
+ if(logger.isDebugEnabled()) {
+ logger.debug(testName + " received " + sOutput);
+ }
+ } finally {
+ res.releaseConnection();
}
}
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"createList", "read"})
public void readList(String testName) throws Exception {
- //FIXME: Should this test really be empty? If so, please comment accordingly.
+ //FIXME: Should this test really be empty? If so, please comment accordingly.
}
// Failure outcomes
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"read", "readList", "readNonExistent"})
public void update(String testName) throws Exception {
- //FIXME: Should this test really be empty? If so, please comment accordingly.
+ //FIXME: Should this test really be empty? If so, please comment accordingly.
}
// Failure outcomes
*/
@Override
public void updateWithEmptyEntityBody(String testName) throws Exception {
- //FIXME: Should this test really be empty? If so, please comment accordingly.
+ //FIXME: Should this test really be empty? If so, please comment accordingly.
}
/* (non-Javadoc)
*/
@Override
public void updateWithMalformedXml(String testName) throws Exception {
- //FIXME: Should this test really be empty? If so, please comment accordingly.
+ //FIXME: Should this test really be empty? If so, please comment accordingly.
}
/* (non-Javadoc)
*/
@Override
public void updateWithWrongXmlSchema(String testName) throws Exception {
- //FIXME: Should this test really be empty? If so, please comment accordingly.
+ //FIXME: Should this test really be empty? If so, please comment accordingly.
}
/* (non-Javadoc)
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"readNonExistent", "testSubmitRequest"})
public void updateNonExistent(String testName) throws Exception {
- //FIXME: Should this test really be empty? If so, please comment accordingly.
+ //FIXME: Should this test really be empty? If so, please comment accordingly.
}
// ---------------------------------------------------------------
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"read"})
public void delete(String testName) throws Exception {
-
+
if (logger.isDebugEnabled()) {
testBanner(testName, CLASS_NAME);
}
-
+
// Perform setup.
setupDelete();
accValues.get("acc-role-user1").getAccountId(), "123");
int statusCode = res.getStatus();
try {
- // Check the status code of the response: does it match
- // the expected response(s)?
- if (logger.isDebugEnabled()) {
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
} finally {
- res.releaseConnection();
+ res.releaseConnection();
}
}
@AfterClass(alwaysRun = true)
@Override
public void cleanUp() {
-
+
setupDelete();
String noTest = System.getProperty("noTestCleanup");
- if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
+ if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
if (logger.isDebugEnabled()) {
logger.debug("Skipping Cleanup phase ...");
}
return;
- }
+ }
if (logger.isDebugEnabled()) {
logger.debug("Cleaning up temporary resources created for testing ...");
}
-
+
AccountRoleClient client = new AccountRoleClient();
for (String resourceId : allResourceIdsCreated) {
ClientResponse<Response> res = client.delete(resourceId, "123");
try {
- int statusCode = res.getStatus();
- if (logger.isDebugEnabled()) {
- logger.debug("clenaup: delete relationships for accission id="
- + resourceId + " status=" + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ int statusCode = res.getStatus();
+ if (logger.isDebugEnabled()) {
+ logger.debug("clenaup: delete relationships for accission id="
+ + resourceId + " status=" + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
} finally {
- res.releaseConnection();
+ res.releaseConnection();
}
}
* @return the string
*/
private String createAccount(String userName, String email) {
-
+
if (logger.isDebugEnabled()) {
testBanner("createAccount");
}
-
+
setupCreate();
-
+
AccountClient accClient = new AccountClient();
AccountsCommon account = AccountFactory.createAccountInstance(
userName, userName, userName, email,
* @param accId the acc id
*/
private void deleteAccount(String accId) {
-
+
if (logger.isDebugEnabled()) {
testBanner("deleteAccount");
}
-
+
setupDelete();
-
+
AccountClient accClient = new AccountClient();
ClientResponse<Response> res = accClient.delete(accId);
int statusCode = res.getStatus();
try {
- if (logger.isDebugEnabled()) {
- logger.debug("deleteAccount: delete account id="
- + accId + " status=" + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ if (logger.isDebugEnabled()) {
+ logger.debug("deleteAccount: delete account id="
+ + accId + " status=" + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
} finally {
- res.releaseConnection();
+ res.releaseConnection();
}
}
ClientResponse<Response> res = roleClient.delete(roleId);
int statusCode = res.getStatus();
try {
- if (logger.isDebugEnabled()) {
- logger.debug("deleteRole: delete role id=" + roleId
- + " status=" + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ if (logger.isDebugEnabled()) {
+ logger.debug("deleteRole: delete role id=" + roleId
+ + " status=" + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
} finally {
- res.releaseConnection();
+ res.releaseConnection();
}
}
}
/** The Constant logger. */
private final static String CLASS_NAME = PermissionRoleServiceTest.class.getName();
private final static Logger logger = LoggerFactory.getLogger(CLASS_NAME);
-
// Instance variables specific to this test.
/** The known resource id. */
private String knownResourceId = null;
private List<String> allResourceIdsCreated = new ArrayList<String>();
final private static String TEST_MARKER = "_PermissionRoleServiceTest";
final private static String TEST_SERVICE_NAME = "fakeservice";
+ final private static String NO_REL_SUFFIX = "-no-rel";
/** The perm values. */
private Hashtable<String, PermissionValue> permValues = new Hashtable<String, PermissionValue>();
/** The role values. */
pva.setPermissionId(accPermId);
permValues.put(pva.getResourceName(), pva);
-// String rc = "collectionobjects";
-// String coPermId = createPermission(rc, EffectType.DENY);
-// PermissionValue pvc = new PermissionValue();
-// pvc.setResourceName(rc);
-// pvc.setPermissionId(coPermId);
-// permValues.put(pvc.getResourceName(), pvc);
+ String rc = TEST_SERVICE_NAME + TEST_MARKER + NO_REL_SUFFIX;
+ String coPermId = createPermission(rc, EffectType.DENY);
+ PermissionValue pvc = new PermissionValue();
+ pvc.setResourceName(rc);
+ pvc.setPermissionId(coPermId);
+ permValues.put(pvc.getResourceName(), pvc);
//
// String ri = "intakes";
// String iPermId = createPermission(ri, EffectType.DENY);
if (logger.isDebugEnabled()) {
logger.debug(testBanner(testName, CLASS_NAME));
}
-
+
// Perform setup, such as initializing the type of service request
// (e.g. CREATE, DELETE), its valid and expected status codes, and
// its associated HTTP method name (e.g. POST, DELETE).
}
}
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ dependsOnMethods = {"create"})
+ public void readNoRelationship(String testName) throws Exception {
+
+ if (logger.isDebugEnabled()) {
+ logger.debug(testBanner(testName, CLASS_NAME));
+ }
+ // Perform setup.
+ setupRead();
+
+ // Submit the request to the service and store the response.
+ PermissionRoleClient client = new PermissionRoleClient();
+ ClientResponse<PermissionRole> res = null;
+ try {
+ res = client.read(
+ permValues.get(TEST_SERVICE_NAME + TEST_MARKER + NO_REL_SUFFIX).getPermissionId(), "123");
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
+
+ PermissionRole output = (PermissionRole) res.getEntity();
+
+ String sOutput = objectAsXmlString(output, PermissionRole.class);
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + " received " + sOutput);
+ }
+ } finally {
+ if (res != null) {
+ res.releaseConnection();
+ }
+ }
+
+ }
// ---------------------------------------------------------------
// CRUD tests : READ_LIST tests
// ---------------------------------------------------------------
/* (non-Javadoc)
* @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
*/
+
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"createList", "read"})
/** The Constant logger. */
private final static String CLASS_NAME = RolePermissionServiceTest.class.getName();
private final static Logger logger = LoggerFactory.getLogger(CLASS_NAME);
-
// Instance variables specific to this test.
/** The known resource id. */
private String knownResourceId = null;
private List<String> allResourceIdsCreated = new ArrayList<String>();
final private static String TEST_MARKER = "_RolePermissionServiceTest";
final private static String TEST_ROLE_NAME = "ROLE";
+ final private static String NO_REL_SUFFIX = "-no-rel";
/** The perm values. */
private Hashtable<String, PermissionValue> permValues = new Hashtable<String, PermissionValue>();
/** The role values. */
private Hashtable<String, RoleValue> roleValues = new Hashtable<String, RoleValue>();
-
private Date now = new Date();
/*
* This method is called only by the parent class, AbstractServiceTestImpl
private String getRoleName() {
return TEST_ROLE_NAME + TEST_MARKER + now.toString();
}
+
/**
* Seed data.
*/
rv1.setRoleName(rn1);
roleValues.put(rv1.getRoleName(), rv1);
+ String rn2 = getRoleName() + NO_REL_SUFFIX;
+ String r2RoleId = createRole(rn2);
+ RoleValue rv2 = new RoleValue();
+ rv2.setRoleId(r2RoleId);
+ rv2.setRoleName(rn2);
+ roleValues.put(rv2.getRoleName(), rv2);
+
String ra1 = "fooService" + TEST_MARKER;
String permId1 = createPermission(ra1, EffectType.PERMIT);
PermissionValue pva1 = new PermissionValue();
if (logger.isDebugEnabled()) {
logger.debug(testBanner(testName, CLASS_NAME));
- };
+ }
+ ;
// Perform setup, such as initializing the type of service request
// (e.g. CREATE, DELETE), its valid and expected status codes, and
// its associated HTTP method name (e.g. POST, DELETE).
if (logger.isDebugEnabled()) {
logger.debug(testBanner(testName, CLASS_NAME));
- };
+ }
+ ;
// Perform setup.
setupRead();
if (logger.isDebugEnabled()) {
logger.debug(testBanner(testName, CLASS_NAME));
- };
+ }
+ ;
// Perform setup.
setupReadNonExistent();
}
}
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
+ public void readNoRelationship(String testName) throws Exception {
+
+ if (logger.isDebugEnabled()) {
+ logger.debug(testBanner(testName, CLASS_NAME));
+ }
+ ;
+ setupRead();
+ // Submit the request to the service and store the response.
+ RolePermissionClient client = new RolePermissionClient();
+ ClientResponse<PermissionRole> res = null;
+ try {
+
+ res = client.read(roleValues.get(getRoleName() + NO_REL_SUFFIX).getRoleId(), "123");
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
+ PermissionRole output = (PermissionRole) res.getEntity();
+
+ String sOutput = objectAsXmlString(output, PermissionRole.class);
+ if(logger.isDebugEnabled()) {
+ logger.debug(testName + " received " + sOutput);
+ }
+ } finally {
+ if (res != null) {
+ res.releaseConnection();
+ }
+ }
+ }
+
// ---------------------------------------------------------------
// CRUD tests : READ_LIST tests
// ---------------------------------------------------------------
if (logger.isDebugEnabled()) {
logger.debug(testBanner(testName, CLASS_NAME));
- };
+ }
+ ;
// Perform setup.
setupDelete();
}
if (getObject(ctx, id) == null) {
String msg = "get: "
- + "could not find the object entity with id=" + id;
+ + "could not find the object with id=" + id;
logger.error(msg);
throw new DocumentNotFoundException(msg);
}
+ String objectId = getObjectId(ctx);
+ if (logger.isDebugEnabled()) {
+ logger.debug("get: using objectId=" + objectId);
+ }
+ Class objectClass = getObjectClass(ctx);
+ if (logger.isDebugEnabled()) {
+ logger.debug("get: using object class=" + objectClass.getName());
+ }
DocumentFilter docFilter = handler.getDocumentFilter();
if (docFilter == null) {
docFilter = handler.createDocumentFilter();
StringBuilder queryStrBldr = new StringBuilder("SELECT a FROM ");
queryStrBldr.append(getEntityName(ctx));
queryStrBldr.append(" a");
- String objectId = getObjectId(ctx);
- if (logger.isDebugEnabled()) {
- logger.debug("get: using objectId=" + objectId);
- }
+
queryStrBldr.append(" WHERE " + objectId + " = :objectId");
String where = docFilter.getWhereClause();
if ((null != where) && (where.length() > 0)) {
if (em != null && em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
- String msg = "get: "
- + " could not find entity with id=" + id;
- logger.error(msg, nre);
- throw new DocumentNotFoundException(msg, nre);
+ String msg = "get(1): "
+ + " could not find relationships for object class="
+ + objectClass.getName() + " id=" + id;
+ if (logger.isDebugEnabled()) {
+ logger.debug(msg, nre);
+ }
}
if (rl.size() == 0) {
- String msg = "get: "
- + " could not find entity with id=" + id;
- logger.error(msg);
- throw new DocumentNotFoundException(msg);
+ String msg = "get(2): "
+ + " could not find relationships for object class="
+ + objectClass.getName() + " id=" + id;
+ if (logger.isDebugEnabled()) {
+ logger.debug(msg);
+ }
}
DocumentWrapper<List<T>> wrapDoc =
new DocumentWrapperImpl<List<T>>(rl);
}
if (getObject(ctx, id) == null) {
String msg = "delete : "
- + "could not find the object entity with id=" + id;
+ + "could not find the object with id=" + id;
logger.error(msg);
throw new DocumentNotFoundException(msg);
}
+ String objectId = getObjectId(ctx);
+ if (logger.isDebugEnabled()) {
+ logger.debug("delete: using objectId=" + objectId);
+ }
+ Class objectClass = getObjectClass(ctx);
+ if (logger.isDebugEnabled()) {
+ logger.debug("delete: using object class=" + objectClass.getName());
+ }
EntityManagerFactory emf = null;
EntityManager em = null;
try {
StringBuilder deleteStr = new StringBuilder("DELETE FROM ");
String entityName = getEntityName(ctx);
deleteStr.append(entityName);
- String objectId = getObjectId(ctx);
- if (logger.isDebugEnabled()) {
- logger.debug("delete: using objectId=" + objectId);
- }
deleteStr.append(" WHERE " + objectId + " = :objectId");
emf = JpaStorageUtils.getEntityManagerFactory();
em = emf.createEntityManager();
protected String getObjectId(ServiceContext ctx) {
String objectId = (String) ctx.getProperty(ServiceContextProperties.OBJECT_ID);
if (objectId == null) {
- String msg = ServiceContextProperties.OBJECT_ID +
- " property is missing in the context";
+ String msg = ServiceContextProperties.OBJECT_ID
+ + " property is missing in the context";
logger.error(msg);
throw new IllegalArgumentException(msg);
}
}
/**
- * getObject returns the object in the relationship
+ * getObjectClass returns the class of the object in a relationship
* @param ctx
- * @param id
* @return
*/
- protected Object getObject(ServiceContext ctx, String id) {
+ protected Class getObjectClass(ServiceContext ctx) {
Class objectClass = (Class) ctx.getProperty(ServiceContextProperties.OBJECT_CLASS);
if (objectClass == null) {
- String msg = ServiceContextProperties.OBJECT_CLASS +
- " property is missing in the context";
+ String msg = ServiceContextProperties.OBJECT_CLASS
+ + " property is missing in the context";
logger.error(msg);
throw new IllegalArgumentException(msg);
}
+ return objectClass;
+ }
+
+ /**
+ * getObject returns the object in the relationship
+ * @param ctx
+ * @param id
+ * @return
+ */
+ protected Object getObject(ServiceContext ctx, String id) {
+ Class objectClass = getObjectClass(ctx);
return JpaStorageUtils.getEntity(id, objectClass);
}
}