--- /dev/null
+/**\r
+ * This document is a part of the source code and related artifacts\r
+ * for CollectionSpace, an open source collections management system\r
+ * for museums and related institutions:\r
+\r
+ * http://www.collectionspace.org\r
+ * http://wiki.collectionspace.org\r
+\r
+ * Copyright 2009 University of California at Berkeley\r
+\r
+ * Licensed under the Educational Community License (ECL), Version 2.0.\r
+ * You may not use this file except in compliance with this License.\r
+\r
+ * You may obtain a copy of the ECL 2.0 License at\r
+\r
+ * https://source.collectionspace.org/collection-space/LICENSE.txt\r
+\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.collectionspace.services.common.document;\r
+\r
+import java.util.List;\r
+/**\r
+ *\r
+ * DocumentWrapper wraps DocumentModel (java) or Representation (REST)\r
+ *\r
+ */\r
+public interface DocumentListWrapper {\r
+\r
+ /**\r
+ * getWrappedObject\r
+ * @return wrapped object\r
+ */\r
+ public List<?> getWrappedObject();\r
+}\r
--- /dev/null
+/**\r
+ * This document is a part of the source code and related artifacts\r
+ * for CollectionSpace, an open source collections management system\r
+ * for museums and related institutions:\r
+\r
+ * http://www.collectionspace.org\r
+ * http://wiki.collectionspace.org\r
+\r
+ * Copyright 2009 University of California at Berkeley\r
+\r
+ * Licensed under the Educational Community License (ECL), Version 2.0.\r
+ * You may not use this file except in compliance with this License.\r
+\r
+ * You may obtain a copy of the ECL 2.0 License at\r
+\r
+ * https://source.collectionspace.org/collection-space/LICENSE.txt\r
+\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.collectionspace.services.common.document;\r
+\r
+import java.util.List;\r
+\r
+// TODO: Auto-generated Javadoc\r
+/**\r
+ * The Class DocumentListWrapperImpl.\r
+ *\r
+ * @param <T> the generic type\r
+ */\r
+public class DocumentListWrapperImpl<T> implements DocumentListWrapper {\r
+\r
+ /** The document list wrapper. */\r
+ private List<T> documentListWrapper;\r
+\r
+ /**\r
+ * Instantiates a new document list wrapper impl.\r
+ *\r
+ * @param theDocumentListWrapper the the document list wrapper\r
+ */\r
+ public DocumentListWrapperImpl(List<T> theDocumentListWrapper) {\r
+ documentListWrapper = theDocumentListWrapper;\r
+ }\r
+\r
+ /* (non-Javadoc)\r
+ * @see org.collectionspace.services.common.document.DocumentListWrapper#getWrappedObject()\r
+ */\r
+ public List<T> getWrappedObject() {\r
+ return documentListWrapper;\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+package org.collectionspace.services.common.query;\r
+\r
+import org.collectionspace.services.common.context.ServiceContext;\r
+import org.collectionspace.services.common.document.DocumentException;\r
+import org.collectionspace.services.common.document.DocumentFilter;\r
+import org.collectionspace.services.common.document.DocumentHandler;\r
+import org.collectionspace.services.common.document.DocumentNotFoundException;\r
+\r
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;\r
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;\r
+\r
+// TODO: Auto-generated Javadoc\r
+/**\r
+ * The Class QueryContext.\r
+ */\r
+public class QueryContext {\r
+\r
+ /** The doc type. */\r
+ String docType;\r
+ /** The doc filter. */\r
+ DocumentFilter docFilter;\r
+ /** The where clause. */\r
+ String whereClause;\r
+ /** The order by clause. */\r
+ String orderByClause;\r
+ /** The domain. */\r
+ String domain;\r
+ /** The tenant id. */\r
+ String tenantId;\r
+\r
+ /**\r
+ * Instantiates a new query context.\r
+ *\r
+ * @param ctx the ctx\r
+ * @throws DocumentNotFoundException the document not found exception\r
+ * @throws DocumentException the document exception\r
+ */\r
+ QueryContext(ServiceContext<MultipartInput, MultipartOutput> ctx) throws DocumentNotFoundException, DocumentException {\r
+ docType = ctx.getDocumentType();\r
+ if (docType == null) {\r
+ throw new DocumentNotFoundException(\r
+ "Unable to find DocumentType for service " + ctx.getServiceName());\r
+ }\r
+ domain = ctx.getRepositoryDomainName();\r
+ tenantId = ctx.getTenantId();\r
+ if (tenantId == null) {\r
+ throw new IllegalArgumentException(\r
+ "Service context has no Tenant ID specified.");\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Instantiates a new query context.\r
+ *\r
+ * @param ctx the ctx\r
+ * @param theWhereClause the where clause\r
+ * @throws DocumentNotFoundException the document not found exception\r
+ * @throws DocumentException the document exception\r
+ */\r
+ public QueryContext(ServiceContext<MultipartInput, MultipartOutput> ctx,\r
+ String theWhereClause) throws DocumentNotFoundException, DocumentException {\r
+ this(ctx);\r
+ whereClause = theWhereClause;\r
+ }\r
+\r
+ /**\r
+ * Instantiates a new query context.\r
+ *\r
+ * @param ctx the ctx\r
+ * @param handler the handler\r
+ * @throws DocumentNotFoundException the document not found exception\r
+ * @throws DocumentException the document exception\r
+ */\r
+ public QueryContext(ServiceContext<MultipartInput, MultipartOutput> ctx,\r
+ DocumentHandler handler) throws DocumentNotFoundException, DocumentException {\r
+ this(ctx);\r
+ if (handler == null) {\r
+ throw new IllegalArgumentException(\r
+ "Document handler is missing.");\r
+ }\r
+ docFilter = handler.getDocumentFilter();\r
+ if (docFilter == null) {\r
+ throw new IllegalArgumentException(\r
+ "Document handler has no Filter specified.");\r
+ }\r
+ whereClause = docFilter.getWhereClause();\r
+ orderByClause = docFilter.getOrderByClause();\r
+ }\r
+ \r
+ /**\r
+ * Gets the doc filter.\r
+ *\r
+ * @return the doc filter\r
+ */\r
+ public DocumentFilter getDocFilter() {\r
+ return docFilter;\r
+ }\r
+ \r
+ /**\r
+ * Gets the where clause.\r
+ *\r
+ * @return the where clause\r
+ */\r
+ public String getWhereClause() {\r
+ return whereClause;\r
+ }\r
+ \r
+ /**\r
+ * Gets the tenant id.\r
+ *\r
+ * @return the tenant id\r
+ */\r
+ public String getTenantId() {\r
+ return this.tenantId;\r
+ }\r
+ \r
+ /**\r
+ * Gets the order by clause.\r
+ *\r
+ * @return the order by clause\r
+ */\r
+ public String getOrderByClause() {\r
+ return this.orderByClause;\r
+ }\r
+ \r
+ /**\r
+ * Gets the doc type.\r
+ *\r
+ * @return the doc type\r
+ */\r
+ public String getDocType() {\r
+ return this.docType;\r
+ }\r
+}\r
--- /dev/null
+package org.collectionspace.services.common.storage.jpa;\r
+\r
+import java.util.List;\r
+\r
+import org.collectionspace.services.common.document.AbstractDocumentHandlerImpl;\r
+import org.collectionspace.services.common.document.DocumentFilter;\r
+import org.collectionspace.services.common.document.DocumentWrapper;\r
+import org.collectionspace.services.hyperjaxb.AbstractCommonList;\r
+\r
+public abstract class JpaDocumentHandler<T, TL, WT, WLT>\r
+ extends AbstractDocumentHandlerImpl<T, TL, WT, WLT>{\r
+\r
+ /**\r
+ * Extract paging info.\r
+ *\r
+ * @param commonsList the commons list\r
+ * @return the tL\r
+ * @throws Exception the exception\r
+ */\r
+ public TL extractPagingInfo(TL theCommonList, DocumentWrapper<WLT> wrapDoc)\r
+ throws Exception {\r
+ AbstractCommonList commonList = (AbstractCommonList) theCommonList;\r
+\r
+ DocumentFilter docFilter = this.getDocumentFilter();\r
+ long pageSize = docFilter.getPageSize();\r
+ long pageNum = pageSize != 0 ? docFilter.getOffset() / pageSize : pageSize;\r
+ // set the page size and page number\r
+ commonList.setPageNum(pageNum);\r
+ commonList.setPageSize(pageSize);\r
+ List docList = (List)wrapDoc.getWrappedObject();\r
+ // Set num of items in list. this is useful to our testing framework.\r
+ commonList.setItemsInPage(docList.size());\r
+ // set the total result size\r
+ commonList.setTotalItems(docList.size());\r
+\r
+ return (TL) commonList;\r
+ } \r
+}\r
--- /dev/null
+//\r
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v3.0-03/04/2009 09:20 AM(valikov)-fcs \r
+// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> \r
+// Any modifications to this file will be lost upon recompilation of the source schema. \r
+// Generated on: 2010.08.19 at 08:39:19 AM PDT \r
+//\r
+\r
+\r
+package org.collectionspace.services.hyperjaxb;\r
+\r
+import javax.xml.bind.annotation.XmlAccessType;\r
+import javax.xml.bind.annotation.XmlAccessorType;\r
+import javax.xml.bind.annotation.XmlRootElement;\r
+import javax.xml.bind.annotation.XmlSchemaType;\r
+import javax.xml.bind.annotation.XmlType;\r
+import org.apache.commons.lang.builder.EqualsBuilder;\r
+import org.apache.commons.lang.builder.HashCodeBuilder;\r
+import org.jvnet.jaxb2_commons.lang.Equals;\r
+import org.jvnet.jaxb2_commons.lang.HashCode;\r
+import org.jvnet.jaxb2_commons.lang.builder.JAXBEqualsBuilder;\r
+import org.jvnet.jaxb2_commons.lang.builder.JAXBHashCodeBuilder;\r
+\r
+\r
+/**\r
+ * \r
+ * \r
+ * \r
+ * <p>Java class for anonymous complex type.\r
+ * \r
+ * <p>The following schema fragment specifies the expected content contained within this class.\r
+ * \r
+ * <pre>\r
+ * <complexType>\r
+ * <complexContent>\r
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">\r
+ * <sequence>\r
+ * <element name="pageNum" type="{http://www.w3.org/2001/XMLSchema}unsignedInt"/>\r
+ * <element name="pageSize" type="{http://www.w3.org/2001/XMLSchema}unsignedInt"/>\r
+ * <element name="itemsInPage" type="{http://www.w3.org/2001/XMLSchema}unsignedInt"/>\r
+ * <element name="totalItems" type="{http://www.w3.org/2001/XMLSchema}unsignedInt"/>\r
+ * </sequence>\r
+ * </restriction>\r
+ * </complexContent>\r
+ * </complexType>\r
+ * </pre>\r
+ * \r
+ * \r
+ */\r
+@XmlAccessorType(XmlAccessType.FIELD)\r
+@XmlType(name = "", propOrder = {\r
+ "pageNum",\r
+ "pageSize",\r
+ "itemsInPage",\r
+ "totalItems"\r
+})\r
+@XmlRootElement(name = "abstract-common-list")\r
+public class AbstractCommonList\r
+ implements Equals, HashCode\r
+{\r
+\r
+ @XmlSchemaType(name = "unsignedInt")\r
+ protected long pageNum;\r
+ @XmlSchemaType(name = "unsignedInt")\r
+ protected long pageSize;\r
+ @XmlSchemaType(name = "unsignedInt")\r
+ protected long itemsInPage;\r
+ @XmlSchemaType(name = "unsignedInt")\r
+ protected long totalItems;\r
+\r
+ /**\r
+ * Gets the value of the pageNum property.\r
+ * \r
+ */\r
+ public long getPageNum() {\r
+ return pageNum;\r
+ }\r
+\r
+ /**\r
+ * Sets the value of the pageNum property.\r
+ * \r
+ */\r
+ public void setPageNum(long value) {\r
+ this.pageNum = value;\r
+ }\r
+\r
+ /**\r
+ * Gets the value of the pageSize property.\r
+ * \r
+ */\r
+ public long getPageSize() {\r
+ return pageSize;\r
+ }\r
+\r
+ /**\r
+ * Sets the value of the pageSize property.\r
+ * \r
+ */\r
+ public void setPageSize(long value) {\r
+ this.pageSize = value;\r
+ }\r
+\r
+ /**\r
+ * Gets the value of the itemsInPage property.\r
+ * \r
+ */\r
+ public long getItemsInPage() {\r
+ return itemsInPage;\r
+ }\r
+\r
+ /**\r
+ * Sets the value of the itemsInPage property.\r
+ * \r
+ */\r
+ public void setItemsInPage(long value) {\r
+ this.itemsInPage = value;\r
+ }\r
+\r
+ /**\r
+ * Gets the value of the totalItems property.\r
+ * \r
+ */\r
+ public long getTotalItems() {\r
+ return totalItems;\r
+ }\r
+\r
+ /**\r
+ * Sets the value of the totalItems property.\r
+ * \r
+ */\r
+ public void setTotalItems(long value) {\r
+ this.totalItems = value;\r
+ }\r
+\r
+ public void equals(Object object, EqualsBuilder equalsBuilder) {\r
+ if (!(object instanceof AbstractCommonList)) {\r
+ equalsBuilder.appendSuper(false);\r
+ return ;\r
+ }\r
+ if (this == object) {\r
+ return ;\r
+ }\r
+ final AbstractCommonList that = ((AbstractCommonList) object);\r
+ equalsBuilder.append(this.getPageNum(), that.getPageNum());\r
+ equalsBuilder.append(this.getPageSize(), that.getPageSize());\r
+ equalsBuilder.append(this.getItemsInPage(), that.getItemsInPage());\r
+ equalsBuilder.append(this.getTotalItems(), that.getTotalItems());\r
+ }\r
+\r
+ public boolean equals(Object object) {\r
+ if (!(object instanceof AbstractCommonList)) {\r
+ return false;\r
+ }\r
+ if (this == object) {\r
+ return true;\r
+ }\r
+ final EqualsBuilder equalsBuilder = new JAXBEqualsBuilder();\r
+ equals(object, equalsBuilder);\r
+ return equalsBuilder.isEquals();\r
+ }\r
+\r
+ public void hashCode(HashCodeBuilder hashCodeBuilder) {\r
+ hashCodeBuilder.append(this.getPageNum());\r
+ hashCodeBuilder.append(this.getPageSize());\r
+ hashCodeBuilder.append(this.getItemsInPage());\r
+ hashCodeBuilder.append(this.getTotalItems());\r
+ }\r
+\r
+ public int hashCode() {\r
+ final HashCodeBuilder hashCodeBuilder = new JAXBHashCodeBuilder();\r
+ hashCode(hashCodeBuilder);\r
+ return hashCodeBuilder.toHashCode();\r
+ }\r
+\r
+}\r