--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.collectionspace.services</groupId>
+ <artifactId>org.collectionspace.services.authorization-mgt</artifactId>
+ <version>5.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>org.collectionspace.services.authorization-mgt.jaxb</artifactId>
+ <name>services.authorization-mgt.jaxb</name>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>com.sun.xml.bind</groupId>
+ <artifactId>jaxb-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jvnet.jaxb2-commons</groupId>
+ <artifactId>property-listener-injector</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.persistence</groupId>
+ <artifactId>persistence-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-entitymanager</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jvnet.hyperjaxb3</groupId>
+ <artifactId>hyperjaxb3-ejb-runtime</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.collectionspace.services</groupId>
+ <artifactId>org.collectionspace.services.jaxb</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.collectionspace.services</groupId>
+ <artifactId>org.collectionspace.services.hyperjaxb</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <finalName>collectionspace-services-authorization-mgt-jaxb</finalName>
+ <defaultGoal>install</defaultGoal>
+ <plugins>
+ <plugin>
+ <!-- maven-hyperjaxb3-plugin generates jaxb + jpa bindings -->
+ <groupId>org.jvnet.hyperjaxb3</groupId>
+ <artifactId>maven-hyperjaxb3-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
+
--- /dev/null
+log4j.rootLogger=debug, stdout, R
+
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+
+# Pattern to output the caller's file name and line number.
+log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n
+
+log4j.appender.R=org.apache.log4j.RollingFileAppender
+log4j.appender.R.File=target/test-client.log
+
+log4j.appender.R.MaxFileSize=100KB
+# Keep one backup file
+log4j.appender.R.MaxBackupIndex=1
+
+log4j.appender.R.layout=org.apache.log4j.PatternLayout
+log4j.appender.R.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n
+
+#packages
+log4j.logger.org.collectionspace=DEBUG
+log4j.logger.org.apache=INFO
+log4j.logger.httpclient=INFO
+log4j.logger.org.jboss.resteasy=INFO
+log4j.logger.org.jvnet.hyperjaxb3=DEBUG
+log4j.logger.org.hibernate=WARN
\ No newline at end of file
import java.util.List;
import java.util.UUID;
+import org.collectionspace.services.account.AccountsCommonList;
import org.collectionspace.services.authorization.PermissionRole;
import org.collectionspace.services.authorization.PermissionRoleSubResource;
import org.collectionspace.services.authorization.PermissionValue;
import org.collectionspace.services.common.document.JaxbUtils;
import org.collectionspace.services.common.security.SecurityUtils;
import org.collectionspace.services.common.storage.jpa.JpaDocumentHandler;
-
+import org.collectionspace.services.jaxb.AbstractCommonList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* @author
*/
public class RoleDocumentHandler
- extends JpaDocumentHandler<Role, RolesList, Role, List> {
+ extends JpaDocumentHandler<Role, RolesList, Role, List<Role>> {
private final Logger logger = LoggerFactory.getLogger(RoleDocumentHandler.class);
private Role role;
private RolesList rolesList;
@Override
public void completeUpdate(DocumentWrapper<Role> wrapDoc) throws Exception {
- Role upAcc = wrapDoc.getWrappedObject();
- getServiceContext().setOutput(upAcc);
- sanitize(upAcc);
+ Role updatedRole = wrapDoc.getWrappedObject();
+ getServiceContext().setOutput(updatedRole);
+ sanitize(updatedRole);
}
@Override
}
@Override
- public void handleGetAll(DocumentWrapper<List> wrapDoc) throws Exception {
+ public void handleGetAll(DocumentWrapper<List<Role>> wrapDoc) throws Exception {
RolesList rolesList = extractCommonPartList(wrapDoc);
setCommonPartList(rolesList);
getServiceContext().setOutput(getCommonPartList());
throw new UnsupportedOperationException("operation not relevant for AccountDocumentHandler");
}
+ /*
+ * See https://issues.collectionspace.org/browse/DRYD-181
+ *
+ * For backward compatibility, we could not change the role list to be a child class of AbstractCommonList. This
+ * would have change the result payload and would break existing API clients. So the best we can do, it treat
+ * the role list payload as a special case and return the paging information.
+ *
+ */
+ protected RolesList extractPagingInfoForRoles(RolesList roleList, DocumentWrapper<List<Role>> wrapDoc)
+ throws Exception {
+
+ DocumentFilter docFilter = this.getDocumentFilter();
+ long pageSize = docFilter.getPageSize();
+ long pageNum = pageSize != 0 ? docFilter.getOffset() / pageSize : pageSize;
+ // set the page size and page number
+ roleList.setPageNum(pageNum);
+ roleList.setPageSize(pageSize);
+ List<Role> docList = wrapDoc.getWrappedObject();
+ // Set num of items in list. this is useful to our testing framework.
+ roleList.setItemsInPage(docList.size());
+ // set the total result size
+ roleList.setTotalItems(docFilter.getTotalItemsResult());
+
+ return roleList;
+ }
+
@Override
public RolesList extractCommonPartList(
- DocumentWrapper<List> wrapDoc)
- throws Exception {
+ DocumentWrapper<List<Role>> wrapDoc) throws Exception {
- RolesList rolesList = new RolesList();
+ RolesList rolesList = extractPagingInfoForRoles(new RolesList(), wrapDoc);
List<Role> list = new ArrayList<Role>();
rolesList.setRole(list);
- for (Object obj : wrapDoc.getWrappedObject()) {
- Role role = (Role) obj;
+ for (Role role : wrapDoc.getWrappedObject()) {
sanitize(role);
list.add(role);
}
+
return rolesList;
}
<xs:annotation>
<xs:documentation>role list</xs:documentation>
</xs:annotation>
+ <xs:element name="pageNum" type="xs:unsignedInt"/>
+ <xs:element name="pageSize" type="xs:unsignedInt"/>
+ <!-- "itemsInPage" is useful to our testing framework's unit tests -->
+ <xs:element name="itemsInPage" type="xs:unsignedInt"/>
+ <xs:element name="totalItems" type="xs:unsignedInt"/>
<xs:element name="role" type="ns:role" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
import javax.persistence.EntityExistsException;
import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
import javax.persistence.NoResultException;
import org.collectionspace.services.authorization.perms.ActionType;
import org.collectionspace.services.authorization.CSpaceAction;
+import org.collectionspace.services.authorization.RolesList;
import org.collectionspace.services.authorization.perms.Permission;
import org.collectionspace.services.authorization.perms.PermissionAction;
import org.collectionspace.services.authorization.perms.PermissionsList;
import org.collectionspace.services.common.security.SecurityUtils;
import org.collectionspace.services.common.storage.jpa.JpaDocumentHandler;
import org.collectionspace.services.common.storage.jpa.JpaStorageUtils;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* @author
*/
public class PermissionDocumentHandler
- extends JpaDocumentHandler<Permission, PermissionsList, Permission, List> {
+ extends JpaDocumentHandler<Permission, PermissionsList, Permission, List<Permission>> {
private final Logger logger = LoggerFactory.getLogger(PermissionDocumentHandler.class);
private Permission permission;
}
@Override
- public void handleGetAll(DocumentWrapper<List> wrapDoc) throws Exception {
+ public void handleGetAll(DocumentWrapper<List<Permission>> wrapDoc) throws Exception {
PermissionsList permissionsList = extractCommonPartList(wrapDoc);
setCommonPartList(permissionsList);
getServiceContext().setOutput(getCommonPartList());
public void completeDelete(DocumentWrapper<Permission> wrapDoc) throws Exception {
}
+ /*
+ * See https://issues.collectionspace.org/browse/DRYD-181
+ *
+ * For backward compatibility, we could not change the permission list to be a child class of AbstractCommonList. This
+ * would have change the result payload and would break existing API clients. So the best we can do, it treat
+ * the role list payload as a special case and return the paging information.
+ *
+ */
+ protected PermissionsList extractPagingInfoForPerms(PermissionsList permList, DocumentWrapper<List<Permission>> wrapDoc)
+ throws Exception {
+
+ DocumentFilter docFilter = this.getDocumentFilter();
+ long pageSize = docFilter.getPageSize();
+ long pageNum = pageSize != 0 ? docFilter.getOffset() / pageSize : pageSize;
+ // set the page size and page number
+ permList.setPageNum(pageNum);
+ permList.setPageSize(pageSize);
+ List<Permission> docList = wrapDoc.getWrappedObject();
+ // Set num of items in list. this is useful to our testing framework.
+ permList.setItemsInPage(docList.size());
+ // set the total result size
+ permList.setTotalItems(docFilter.getTotalItemsResult());
+
+ return permList;
+ }
+
@Override
public Permission extractCommonPart(
DocumentWrapper<Permission> wrapDoc)
@Override
public PermissionsList extractCommonPartList(
- DocumentWrapper<List> wrapDoc)
+ DocumentWrapper<List<Permission>> wrapDoc)
throws Exception {
- PermissionsList permissionsList = new PermissionsList();
+ PermissionsList permissionsList = extractPagingInfoForPerms(new PermissionsList(), wrapDoc);
List<Permission> list = new ArrayList<Permission>();
permissionsList.setPermission(list);
for (Object obj : wrapDoc.getWrappedObject()) {
sanitize(permission);
list.add(permission);
}
+
return permissionsList;
}
/** The page size. */
protected int pageSize; // Pagination limit for list results
+ /** The total number of items for a query result -independent of paging restrictions.
+ *
+ */
+ protected long totalItemsResult = -1;
+
//queryParams is not initialized as it would require a multi-valued map implementation
//unless it is used from opensource lib...this variable holds ref to
//implementation available in JBoss RESTeasy
protected String getTenantId() {
return AuthN.get().getCurrentTenantId();
}
+
+ /*
+ * Used to set the total number of items matching a query -independent of the paging restrictions.
+ */
+ public void setTotalItemsResult(long totalItems) {
+ totalItemsResult = totalItems;
+ }
+
+ /*
+ * Used to get the total number of items matching the last query made -independent of the paging restrictions.
+ */
+ public long getTotalItemsResult() {
+ return totalItemsResult;
+ }
}
// Set num of items in list. this is useful to our testing framework.
commonList.setItemsInPage(docList.size());
// set the total result size
- commonList.setTotalItems(docList.size());
+ commonList.setTotalItems(docFilter.getTotalItemsResult());
return (TL) commonList;
}
//FIXME is transaction required for get?
em.getTransaction().begin();
List list = q.getResultList();
+ long totalItems = getTotalItems(em, ctx, handler); // Find out how many items our query would find independent of the paging restrictions
em.getTransaction().commit();
+
+ docFilter.setTotalItemsResult(totalItems); // Save the items total in the doc filter for later reporting
+
DocumentWrapper<List> wrapDoc = new DocumentWrapperImpl<List>(list);
handler.handle(Action.GET_ALL, wrapDoc);
handler.complete(Action.GET_ALL, wrapDoc);
}
}
- /* (non-Javadoc)
+ /*
+ * Return the COUNT for a query to find the total number of matches independent of the paging restrictions.
+ */
+ private long getTotalItems(EntityManager em, ServiceContext ctx, DocumentHandler handler) {
+ long result = -1;
+
+ DocumentFilter docFilter = handler.getDocumentFilter();
+ StringBuilder queryStrBldr = new StringBuilder("SELECT COUNT(*) FROM ");
+ queryStrBldr.append(getEntityName(ctx));
+ queryStrBldr.append(" a");
+
+ List<DocumentFilter.ParamBinding> params = docFilter.buildWhereForSearch(queryStrBldr);
+ String queryStr = queryStrBldr.toString();
+ Query q = em.createQuery(queryStr);
+ //bind parameters
+ for (DocumentFilter.ParamBinding p : params) {
+ q.setParameter(p.getName(), p.getValue());
+ }
+
+ result = (long) q.getSingleResult();
+
+ return result;
+ }
+
+ /* (non-Javadoc)
* @see org.collectionspace.services.common.storage.StorageClient#update(org.collectionspace.services.common.context.ServiceContext, java.lang.String, org.collectionspace.services.common.document.DocumentHandler)
*/
@Override
<xs:annotation>
<xs:documentation>permission configuration list</xs:documentation>
</xs:annotation>
+ <xs:element name="pageNum" type="xs:unsignedInt"/>
+ <xs:element name="pageSize" type="xs:unsignedInt"/>
+ <!-- "itemsInPage" is useful to our testing framework's unit tests -->
+ <xs:element name="itemsInPage" type="xs:unsignedInt"/>
+ <xs:element name="totalItems" type="xs:unsignedInt"/>
<xs:element name="permission" type="ns:permission" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>