>();
- if (!objsCreated.isEmpty()) {
- actionMap.put(ActionTypes.create, objsCreated);
- }
- if (!objsVersioned.isEmpty()) {
- actionMap.put(ActionTypes.version, objsVersioned);
- }
- if (!objsUpdated.isEmpty()) {
- actionMap.put(ActionTypes.update, objsUpdated);
- }
- auditableEventService.createAuditableEventsFromObjects(request,
- actionMap, System.currentTimeMillis());
+ auditableEventService.createAuditableEventFromObjects(request,
+ objsCreated, objsUpdated, null, null);
} catch (EbxmlRegistryException e) {
response.getException()
.add(EbxmlExceptionUtil
@@ -637,6 +547,18 @@ public class LifecycleManagerImpl implements LifecycleManager {
}
+ /**
+ * Verifies that the service adheres to the spec when dealing with replicas
+ *
+ * @param request
+ * The request
+ * @param object1
+ * The object being submitted
+ * @param object2
+ * The current object in the registry
+ * @throws MsgRegistryException
+ * If errors occur while checking for replicas
+ */
private void checkReplica(SubmitObjectsRequest request,
RegistryObjectType object1, RegistryObjectType object2)
throws MsgRegistryException {
@@ -647,7 +569,8 @@ public class LifecycleManagerImpl implements LifecycleManager {
String object2Home = object2
.getSlotValue(EbxmlObjectUtil.HOME_SLOT_NAME);
- if (object1.getOwner().equals(object2.getOwner())) {
+ if (object1.getOwner() != null
+ && (object1.getOwner().equals(object2.getOwner()))) {
return;
}
if (fromNotification) {
@@ -741,4 +664,8 @@ public class LifecycleManagerImpl implements LifecycleManager {
this.registryObjectDao = registryObjectDao;
}
+ public void setReferenceResolver(ObjectReferenceResolver referenceResolver) {
+ this.referenceResolver = referenceResolver;
+ }
+
}
diff --git a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/lifecycle/ObjectReferenceResolver.java b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/lifecycle/ObjectReferenceResolver.java
new file mode 100644
index 0000000000..e259049853
--- /dev/null
+++ b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/lifecycle/ObjectReferenceResolver.java
@@ -0,0 +1,288 @@
+/**
+ * This software was developed and / or modified by Raytheon Company,
+ * pursuant to Contract DG133W-05-CQ-1067 with the US Government.
+ *
+ * U.S. EXPORT CONTROLLED TECHNICAL DATA
+ * This software product contains export-restricted data whose
+ * export/transfer/disclosure is restricted by U.S. law. Dissemination
+ * to non-U.S. persons whether in the United States or abroad requires
+ * an export license or other authorization.
+ *
+ * Contractor Name: Raytheon Company
+ * Contractor Address: 6825 Pine Street, Suite 340
+ * Mail Stop B8
+ * Omaha, NE 68106
+ * 402.291.0100
+ *
+ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for
+ * further licensing information.
+ **/
+package com.raytheon.uf.edex.registry.ebxml.services.lifecycle;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import oasis.names.tc.ebxml.regrep.wsdl.registry.services.v4.MsgRegistryException;
+import oasis.names.tc.ebxml.regrep.wsdl.registry.services.v4.QueryManager;
+import oasis.names.tc.ebxml.regrep.xsd.query.v4.QueryRequest;
+import oasis.names.tc.ebxml.regrep.xsd.query.v4.QueryResponse;
+import oasis.names.tc.ebxml.regrep.xsd.rim.v4.DynamicObjectRefType;
+import oasis.names.tc.ebxml.regrep.xsd.rim.v4.QueryType;
+import oasis.names.tc.ebxml.regrep.xsd.rim.v4.RegistryObjectType;
+import oasis.names.tc.ebxml.regrep.xsd.rs.v4.RegistryExceptionType;
+
+import org.apache.commons.beanutils.PropertyUtils;
+import org.apache.commons.validator.UrlValidator;
+
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.raytheon.uf.common.registry.constants.ErrorSeverity;
+import com.raytheon.uf.common.registry.schemas.ebxml.util.annotations.RegistryObjectReference;
+import com.raytheon.uf.common.registry.services.RegistryRESTServices;
+import com.raytheon.uf.common.status.IUFStatusHandler;
+import com.raytheon.uf.common.status.UFStatus;
+import com.raytheon.uf.edex.registry.ebxml.dao.DynamicObjectRefDao;
+import com.raytheon.uf.edex.registry.ebxml.dao.RegistryObjectDao;
+import com.raytheon.uf.edex.registry.ebxml.exception.EbxmlRegistryException;
+import com.raytheon.uf.edex.registry.ebxml.util.EbxmlExceptionUtil;
+
+/**
+ *
+ * Utility class used to resolve references contained in registry objects
+ *
+ *
+ *
+ * SOFTWARE HISTORY
+ *
+ * Date Ticket# Engineer Description
+ * ------------ ---------- ----------- --------------------------
+ * 7/2312013 2191 bphillip Initial implementation
+ *
+ *
+ * @author bphillip
+ * @version 1
+ */
+public class ObjectReferenceResolver {
+
+ /** The logger */
+ private static final IUFStatusHandler statusHandler = UFStatus
+ .getHandler(ObjectReferenceResolver.class);
+
+ /** Data access object for registry objects */
+ private RegistryObjectDao registryObjectDao;
+
+ /** Data access object for dynamic reference objects */
+ private DynamicObjectRefDao dynamicRefDao;
+
+ /** Query Manager service */
+ private QueryManager queryManager;
+
+ /** Validator for validating REST endpoint addresses */
+ private UrlValidator urlValidator = new UrlValidator();
+
+ /** Cache holding the fields in each class that are object references */
+ private static LoadingCache, List> OBJECT_REFERENCE_FIELD_CACHE = CacheBuilder
+ .newBuilder().expireAfterAccess(1, TimeUnit.MINUTES)
+ .build(new CacheLoader, List>() {
+ @Override
+ public List load(Class> clazz) throws Exception {
+ List fields = new ArrayList();
+ while (!clazz.equals(Object.class)) {
+ for (Field f : clazz.getDeclaredFields()) {
+ if (f.isAnnotationPresent(RegistryObjectReference.class)) {
+ fields.add(f.getName());
+ }
+ }
+ clazz = clazz.getSuperclass();
+ }
+ return fields;
+ }
+ });
+
+ /**
+ * Validates the list of objects and makes sure all fields referencing
+ * objects can be resolved.
+ *
+ * @param regObjs
+ * The list of objects to check references for
+ * @throws MsgRegistryException
+ * If any or all of the objects in the list contain unresolved
+ * references
+ */
+ public void checkReferences(List regObjs)
+ throws MsgRegistryException {
+ for (RegistryObjectType regObj : regObjs) {
+ statusHandler.info("Checking references for object: "
+ + regObj.getId() + "...");
+ try {
+ List fields = OBJECT_REFERENCE_FIELD_CACHE.get(regObj
+ .getClass());
+ for (String field : fields) {
+ String propertyValue = (String) PropertyUtils.getProperty(
+ regObj, field);
+ if (propertyValue == null) {
+ continue;
+ }
+
+ // Check for static reference first
+ if (isStaticReference(regObj, propertyValue)
+ || isDynamicReference(regObj, field, propertyValue)
+ || isRESTReference(regObj, propertyValue)) {
+ continue;
+ }
+ throw EbxmlExceptionUtil.createMsgRegistryException(
+ "Object [" + regObj.getId()
+ + "] references unresolvable object ["
+ + propertyValue + "]", EbxmlExceptionUtil
+ .createUnresolvedReferenceException(
+ regObj.getClass(), regObj.getId(),
+ statusHandler), statusHandler);
+ }
+
+ } catch (MsgRegistryException e) {
+ throw e;
+ } catch (Exception e) {
+
+ throw EbxmlExceptionUtil.createMsgRegistryException(
+ "Error checking references", EbxmlExceptionUtil
+ .createRegistryException(
+ RegistryExceptionType.class, "",
+ "Error checking references",
+ "Error checking references",
+ ErrorSeverity.ERROR, e, statusHandler),
+ statusHandler);
+ }
+ }
+ }
+
+ /**
+ * Checks if the object specified by ref on the object obj is a static
+ * reference
+ *
+ * @param obj
+ * The object being checked
+ * @param ref
+ * The string to check if it is a static reference
+ * @return true if the item is a static reference and the object exists.
+ * False if the object is not a static reference
+ */
+ private boolean isStaticReference(RegistryObjectType obj, String ref) {
+ return registryObjectDao.getById(ref) != null;
+ }
+
+ /**
+ * Checks if the property is a dynamic reference
+ *
+ * @param obj
+ * The object being checked
+ * @param propertyName
+ * The property on the object being checked
+ * @param ref
+ * The value of the property on the object being checked
+ * @return True if this is a dynamic reference and the referenced object can
+ * be resolved
+ * @throws MsgRegistryException
+ * If issues occur while executing the query via the query
+ * manager
+ * @throws EbxmlRegistryException
+ * If too many results were returned by the dynamic reference
+ * query
+ */
+ private boolean isDynamicReference(RegistryObjectType obj,
+ String propertyName, String ref) throws MsgRegistryException,
+ EbxmlRegistryException {
+ DynamicObjectRefType dynamicRef = dynamicRefDao.getById(ref);
+ if (dynamicRef != null) {
+ QueryType refQuery = dynamicRef.getQuery();
+ if (refQuery != null) {
+ QueryRequest queryRequest = new QueryRequest();
+ queryRequest
+ .setId("Dynamic reference resolution query request");
+ queryRequest.setComment("Resolving property [" + propertyName
+ + " -> " + ref + "] on object [" + obj.getId() + "]");
+ queryRequest.setQuery(refQuery);
+ QueryResponse queryResponse = queryManager
+ .executeQuery(queryRequest);
+ return responseOk(queryResponse);
+
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Checks if this is a object reference which references a REST service
+ *
+ * @param obj
+ * The object being checked
+ * @param ref
+ * The value being checked
+ * @return True if this is a REST reference and the object being referenced
+ * can be resolved, else false
+ * @throws EbxmlRegistryException
+ * If too many results were returned by the REST call or an
+ * unexpected type was returned by the REST call
+ */
+ private boolean isRESTReference(RegistryObjectType obj, String ref)
+ throws EbxmlRegistryException {
+ if (urlValidator.isValid(ref)) {
+ Object restResponse = RegistryRESTServices
+ .accessXMLRestService(ref);
+ if (restResponse instanceof QueryResponse) {
+ return responseOk((QueryResponse) restResponse);
+ } else if (restResponse instanceof RegistryObjectType) {
+ return true;
+ } else {
+ throw new EbxmlRegistryException("Unexpected response from "
+ + ref + ". Received response of type: "
+ + restResponse.getClass());
+ }
+ } else {
+ return false;
+ }
+
+ }
+
+ /**
+ * Checks if a query response is ok. The response is ok if the query result
+ * is of size 1
+ *
+ * @param queryResponse
+ * The query response to check
+ * @return True if the query returned a single result
+ * @throws EbxmlRegistryException
+ * If the query returned too many results
+ */
+ private boolean responseOk(QueryResponse queryResponse)
+ throws EbxmlRegistryException {
+ if (queryResponse.isOk()) {
+ List responseObjects = queryResponse
+ .getRegistryObjects();
+ if (responseObjects.isEmpty()) {
+ return false;
+ } else if (responseObjects.size() > 1) {
+ throw new EbxmlRegistryException(
+ "DynamicObjReference query returned too many results. Expected 1. Got "
+ + responseObjects.size());
+ }
+ return true;
+ }
+ return false;
+ }
+
+ public void setRegistryObjectDao(RegistryObjectDao registryObjectDao) {
+ this.registryObjectDao = registryObjectDao;
+ }
+
+ public void setDynamicRefDao(DynamicObjectRefDao dynamicRefDao) {
+ this.dynamicRefDao = dynamicRefDao;
+ }
+
+ public void setQueryManager(QueryManager queryManager) {
+ this.queryManager = queryManager;
+ }
+
+}
diff --git a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/query/types/canonical/BasicQuery.java b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/query/types/canonical/BasicQuery.java
index a671223eb6..31846cc8ee 100644
--- a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/query/types/canonical/BasicQuery.java
+++ b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/query/types/canonical/BasicQuery.java
@@ -94,6 +94,7 @@ import com.raytheon.uf.edex.registry.ebxml.services.query.types.CanonicalEbxmlQu
* 2/13/2012 #184 bphillip Initial creation
* 3/18/2013 1802 bphillip Modified to use transaction boundaries and spring dao injection
* 4/9/2013 1802 bphillip Changed abstract method signature, modified return processing, and changed static variables
+ * 8/1/2013 1693 bphillip Fixed minor typo
*
*
*
@@ -188,7 +189,7 @@ public class BasicQuery extends CanonicalEbxmlQuery {
query.append(conjunction);
}
if (name != null) {
- query.append("names.value='").append(description).append("'");
+ query.append("names.value='").append(name).append("'");
query.append(conjunction);
}
if (objectType != null) {
diff --git a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/query/types/canonical/FindAssociations.java b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/query/types/canonical/FindAssociations.java
index 26445ef4a1..1977194c91 100644
--- a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/query/types/canonical/FindAssociations.java
+++ b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/query/types/canonical/FindAssociations.java
@@ -75,6 +75,7 @@ import com.raytheon.uf.edex.registry.ebxml.services.query.types.CanonicalEbxmlQu
* 2/13/2012 #184 bphillip Initial creation
* 3/18/2013 1802 bphillip Modified to use transaction boundaries and spring dao injection
* 4/9/2013 1802 bphillip Changed abstract method signature, modified return processing, and changed static variables
+ * 8/1/2013 1693 bphilip Fixed minor typo
*
*
*
@@ -148,7 +149,7 @@ public class FindAssociations extends CanonicalEbxmlQuery {
if (sourceObjectType != null) {
List ids = registryObjectDao
.executeHQLQuery("select id from RegistryObjectType obj where obj.objectType = '"
- + targetObjectType + "'");
+ + sourceObjectType + "'");
if (ids.isEmpty()) {
return;
} else {
diff --git a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/util/EbxmlExceptionUtil.java b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/util/EbxmlExceptionUtil.java
index 1cf8f03ba0..ffce692ede 100644
--- a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/util/EbxmlExceptionUtil.java
+++ b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/util/EbxmlExceptionUtil.java
@@ -26,6 +26,8 @@ import java.lang.reflect.InvocationTargetException;
import oasis.names.tc.ebxml.regrep.wsdl.registry.services.v4.MsgRegistryException;
import oasis.names.tc.ebxml.regrep.xsd.rim.v4.RegistryObjectType;
+import oasis.names.tc.ebxml.regrep.xsd.rs.v4.InvalidRequestExceptionType;
+import oasis.names.tc.ebxml.regrep.xsd.rs.v4.ObjectExistsExceptionType;
import oasis.names.tc.ebxml.regrep.xsd.rs.v4.RegistryExceptionType;
import oasis.names.tc.ebxml.regrep.xsd.rs.v4.UnresolvedReferenceExceptionType;
@@ -46,6 +48,7 @@ import com.raytheon.uf.edex.registry.ebxml.exception.EbxmlRegistryException;
* ------------ ---------- ----------- --------------------------
* Jan 19, 2012 184 bphillip Initial creation
* Apr 23, 2013 1910 djohnson Add createUnresolvedReferenceException().
+ * 8/1/2013 1693 bphillip Added methods to create exceptions
*
*
*
@@ -293,12 +296,25 @@ public class EbxmlExceptionUtil {
Class extends RegistryObjectType> referencedObjectType,
String id, IUFStatusHandler statusHandler) {
final String ofType = (referencedObjectType == null) ? "" : "to type ["
- + referencedObjectType.getCanonicalName()
- + "] ";
+ + referencedObjectType.getCanonicalName() + "] ";
final String message = "Registry object reference " + ofType
+ "with id [" + id + "] was unresolved";
return createRegistryException(UnresolvedReferenceExceptionType.class,
"", "Unresolved reference found", message, ErrorSeverity.ERROR,
statusHandler);
}
+
+ public static MsgRegistryException createInvalidRequestException(
+ String message) {
+ InvalidRequestExceptionType invalidRequestException = new InvalidRequestExceptionType();
+ invalidRequestException.setMessage(message);
+ return new MsgRegistryException(message, invalidRequestException);
+ }
+
+ public static MsgRegistryException createObjectExistsException(
+ String message) {
+ ObjectExistsExceptionType objectExistsException = new ObjectExistsExceptionType();
+ objectExistsException.setMessage(message);
+ return new MsgRegistryException(message, objectExistsException);
+ }
}
diff --git a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/util/EbxmlObjectUtil.java b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/util/EbxmlObjectUtil.java
index 79e6e5788c..ba7de0a484 100644
--- a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/util/EbxmlObjectUtil.java
+++ b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/util/EbxmlObjectUtil.java
@@ -46,7 +46,6 @@ import oasis.names.tc.ebxml.regrep.xsd.rim.v4.RegistryObjectType;
import oasis.names.tc.ebxml.regrep.xsd.rim.v4.SlotType;
import oasis.names.tc.ebxml.regrep.xsd.rim.v4.StringValueType;
import oasis.names.tc.ebxml.regrep.xsd.rim.v4.ValueType;
-import oasis.names.tc.ebxml.regrep.xsd.rim.v4.VersionInfoType;
import org.apache.cxf.headers.Header;
import org.apache.cxf.helpers.CastUtils;
@@ -67,6 +66,7 @@ import com.raytheon.uf.edex.registry.ebxml.exception.EbxmlRegistryException;
* Jan 18, 2012 184 bphillip Initial creation
* 3/18/2013 1082 bphillip Removed utility methods for VersionInfoType
* 4/9/2013 1802 bphillip Removed unused methods and addded a few new ones
+ * 8/1/2013 1693 bphillip Removed increment version method
*
*
*
@@ -277,16 +277,6 @@ public class EbxmlObjectUtil {
return classes;
}
- public static VersionInfoType incrementVersion(
- VersionInfoType existingVersion) {
- String newVersion = String.valueOf(Integer.parseInt(existingVersion
- .getVersionName()) + 1);
- VersionInfoType versionObj = new VersionInfoType();
- versionObj.setVersionName(newVersion);
- versionObj.setUserVersionName(existingVersion.getUserVersionName());
- return versionObj;
- }
-
public static List getIdsFromObjectRefListType(
ObjectRefListType refList) {
if (refList == null) {
diff --git a/edexOsgi/com.raytheon.uf.edex.stats/src/com/raytheon/uf/edex/stats/dao/AggregateRecordDao.java b/edexOsgi/com.raytheon.uf.edex.stats/src/com/raytheon/uf/edex/stats/dao/AggregateRecordDao.java
index 23514bc758..9e9bd5c229 100644
--- a/edexOsgi/com.raytheon.uf.edex.stats/src/com/raytheon/uf/edex/stats/dao/AggregateRecordDao.java
+++ b/edexOsgi/com.raytheon.uf.edex.stats/src/com/raytheon/uf/edex/stats/dao/AggregateRecordDao.java
@@ -41,6 +41,7 @@ import com.raytheon.uf.edex.database.dao.SessionManagedDao;
* Aug 21, 2012 jsanchez Initial creation
* Mar 18, 2013 1082 bphillip Modified to extend sessionmanagedDao and use spring injection
* May 22, 2013 1917 rjpeter Added query methods for retrieving data about aggregates.
+ * 8/1/2013 1693 bphillip Fixed named parameters in queries
*
*
* @author jsanchez
@@ -143,11 +144,14 @@ public class AggregateRecordDao extends
public List getAggregates(final String eventType,
final Date startDate, final Date endDate)
throws DataAccessLayerException {
- String hql = "FROM AggregateRecord WHERE eventType = :eventType AND startDate >= minStart AND startDate < maxStart ORDER BY startDate";
+ String hql = "FROM AggregateRecord WHERE eventType = :eventType AND startDate >= :minStart AND startDate < :maxStart ORDER BY startDate";
try {
+ Calendar start = Calendar.getInstance();
+ start.setTime(startDate);
+ Calendar end = Calendar.getInstance();
+ end.setTime(endDate);
List results = this.executeHQLQuery(hql,
- "eventType", eventType, "minStart", startDate, "maxStart",
- endDate);
+ "eventType", eventType, "minStart", start, "maxStart", end);
return results;
} catch (Exception e) {
throw new DataAccessLayerException(