import static org.nuxeo.elasticsearch.ElasticSearchConstants.ES_ENABLED_PROPERTY;
import javax.servlet.ServletContextEvent;
+import javax.ws.rs.core.PathSegment;
import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
import org.jboss.resteasy.core.Dispatcher;
import org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap;
-
+import org.jboss.resteasy.specimpl.PathSegmentImpl;
+import org.collectionspace.authentication.AuthN;
import org.collectionspace.authentication.CSpaceTenant;
import org.collectionspace.services.account.Tenant;
import org.collectionspace.services.account.TenantResource;
import org.collectionspace.services.authorization.AuthZ;
+import org.collectionspace.services.client.AbstractCommonListUtils;
import org.collectionspace.services.client.AuthorityClient;
-
+import org.collectionspace.services.client.CollectionSpaceClient;
+import org.collectionspace.services.client.PayloadOutputPart;
+import org.collectionspace.services.client.PoxPayloadOut;
+import org.collectionspace.services.client.ReportClient;
+import org.collectionspace.services.client.workflow.WorkflowClient;
import org.collectionspace.services.common.CSWebApplicationException;
import org.collectionspace.services.common.ResourceMap;
import org.collectionspace.services.common.ServiceMain;
import org.collectionspace.services.common.api.RefName;
import org.collectionspace.services.common.config.ConfigUtils;
import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl;
+import org.collectionspace.services.common.query.UriInfoImpl;
import org.collectionspace.services.common.vocabulary.AuthorityResource;
import org.collectionspace.services.config.service.AuthorityInstanceType;
import org.collectionspace.services.config.service.Term;
import org.collectionspace.services.config.service.TermList;
import org.collectionspace.services.config.tenant.TenantBindingType;
+import org.collectionspace.services.config.types.PropertyItemType;
+import org.collectionspace.services.config.types.PropertyType;
+import org.collectionspace.services.jaxb.AbstractCommonList;
+import org.collectionspace.services.jaxb.AbstractCommonList.ListItem;
import org.collectionspace.services.nuxeo.util.NuxeoUtils;
-
+import org.collectionspace.services.report.ReportResource;
import org.nuxeo.elasticsearch.ElasticSearchComponent;
import org.nuxeo.elasticsearch.api.ElasticSearchService;
import org.nuxeo.runtime.api.Framework;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.io.File;
import java.lang.reflect.Constructor;
-import java.util.Date;
+import java.net.URI;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.util.Arrays;
+import java.util.HashSet;
import java.util.Hashtable;
import java.util.List;
-import java.util.logging.Level;
+import java.util.Set;
public class CSpaceResteasyBootstrap extends ResteasyBootstrap {
+ private static final Logger logger = LoggerFactory.getLogger(CSpaceResteasyBootstrap.class);
- java.util.logging.Logger logger = java.util.logging.Logger.getAnonymousLogger();
- static final String RESET_AUTHORITIES_PROPERTY = "org.collectionspace.services.authorities.reset";
+ private static final String RESET_AUTHORITIES_PROPERTY = "org.collectionspace.services.authorities.reset";
private static final String RESET_ELASTICSEARCH_INDEX_PROPERTY = "org.collectionspace.services.elasticsearch.reset";
+ private static final String RESET_REPORTS_PROPERTY = "org.collectionspace.services.reports.reset";
private static final String QUICK_BOOT_PROPERTY = "org.collectionspace.services.quickboot";
+ private static final String REPORT_PROPERTY = "report";
@Override
- public void contextInitialized(ServletContextEvent event) {
+ public void contextInitialized(ServletContextEvent event) {
try {
//
- // This call to super instantiates and initializes our JAX-RS application class.
- // The application class is org.collectionspace.services.jaxrs.CollectionSpaceJaxRsApplication.
- //
- logger.log(Level.INFO, String.format("%tc [INFO] Starting up the CollectionSpace Services' JAX-RS application.", new Date()));
+ // This call to super instantiates and initializes our JAX-RS application class.
+ // The application class is org.collectionspace.services.jaxrs.CollectionSpaceJaxRsApplication.
+ //
+ logger.info("Starting up the CollectionSpace Services JAX-RS application.");
super.contextInitialized(event);
CollectionSpaceJaxRsApplication app = (CollectionSpaceJaxRsApplication)deployment.getApplication();
Dispatcher disp = deployment.getDispatcher();
disp.getDefaultContextObjects().put(ResourceMap.class, app.getResourceMap());
- String quickBoot = System.getProperty(QUICK_BOOT_PROPERTY, Boolean.FALSE.toString()); // Property can be set in the tomcat/bin/setenv.sh (or setenv.bat) file
+ // Property can be set in the tomcat/bin/setenv.sh (or setenv.bat) file
+ String quickBoot = System.getProperty(QUICK_BOOT_PROPERTY, Boolean.FALSE.toString());
+
if (Boolean.valueOf(quickBoot) == false) {
- String resetAuthsString = System.getProperty(RESET_AUTHORITIES_PROPERTY, Boolean.FALSE.toString()); // Property can be set in the tomcat/bin/setenv.sh (or setenv.bat) file
- initializeAuthorities(app.getResourceMap(), Boolean.valueOf(resetAuthsString));
+ // The below properties can be set in the tomcat/bin/setenv.sh (or setenv.bat) file.
+ String resetAuthsString = System.getProperty(RESET_AUTHORITIES_PROPERTY, Boolean.FALSE.toString());
+ String resetElasticsearchIndexString = System.getProperty(RESET_ELASTICSEARCH_INDEX_PROPERTY, Boolean.FALSE.toString());
+ String resetReportsString = System.getProperty(RESET_REPORTS_PROPERTY, Boolean.TRUE.toString());
- String resetElasticsearchIndexString = System.getProperty(RESET_ELASTICSEARCH_INDEX_PROPERTY, Boolean.FALSE.toString()); // Property can be set in the tomcat/bin/setenv.sh (or setenv.bat) file
+ initializeAuthorities(app.getResourceMap(), Boolean.valueOf(resetAuthsString));
if (Boolean.valueOf(resetElasticsearchIndexString) == true) {
resetElasticSearchIndex();
}
+
+ if (Boolean.valueOf(resetReportsString) == true) {
+ resetReports();
+ }
}
- logger.log(Level.INFO, String.format("%tc [INFO] CollectionSpace Services' JAX-RS application started.", new Date()));
+ logger.info("CollectionSpace Services JAX-RS application started.");
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
@Override
public void contextDestroyed(ServletContextEvent event) {
- logger.log(Level.INFO, "[INFO] Shutting down the CollectionSpace Services' JAX-RS application.");
+ logger.info("Shutting down the CollectionSpace Services JAX-RS application.");
//Do something if needed.
- logger.log(Level.INFO, "[INFO] CollectionSpace Services' JAX-RS application stopped.");
+ logger.info("CollectionSpace Services JAX-RS application stopped.");
+ }
+
+ public void resetReports() throws Exception {
+ logger.info("Resetting reports");
+
+ TenantBindingConfigReaderImpl tenantBindingConfigReader = ServiceMain.getInstance().getTenantBindingConfigReader();
+ Hashtable<String, TenantBindingType> tenantBindingsTable = tenantBindingConfigReader.getTenantBindings(false);
+
+ for (TenantBindingType tenantBinding : tenantBindingsTable.values()) {
+ ServiceBindingType reportServiceBinding = null;
+
+ for (ServiceBindingType serviceBinding : tenantBinding.getServiceBindings()) {
+ if (serviceBinding.getName().toLowerCase().trim().equals(ReportClient.SERVICE_NAME)) {
+ reportServiceBinding = serviceBinding;
+
+ break;
+ }
+ }
+
+ Set<String> reportNames = new HashSet<String>();
+
+ if (reportServiceBinding != null) {
+ for (PropertyType property : reportServiceBinding.getProperties()) {
+ for (PropertyItemType item : property.getItem()) {
+ if (item.getKey().equals(REPORT_PROPERTY)) {
+ reportNames.add(item.getValue());
+ }
+ }
+ }
+ }
+
+ if (reportNames.size() > 0) {
+ CSpaceTenant tenant = new CSpaceTenant(tenantBinding.getId(), tenantBinding.getName());
+
+ resetTenantReports(tenant, reportNames);
+ }
+ }
+ }
+
+ private void resetTenantReports(CSpaceTenant tenant, Set<String> reportNames) throws Exception {
+ logger.info("Resetting reports for tenant {}", tenant.getId());
+
+ AuthZ.get().login(tenant);
+
+ CollectionSpaceJaxRsApplication app = (CollectionSpaceJaxRsApplication) deployment.getApplication();
+ ResourceMap resourceMap = app.getResourceMap();
+ ReportResource reportResource = (ReportResource) resourceMap.get(ReportClient.SERVICE_NAME);
+
+ for (String reportName : reportNames) {
+ File reportMetadataFile = ReportResource.getReportMetadataFile(reportName);
+
+ if (!reportMetadataFile.exists()) {
+ logger.warn(
+ "Metadata file not found for report {} at {}",
+ reportName, reportMetadataFile.getAbsolutePath());
+
+ continue;
+ }
+
+ String payload = new String(Files.readAllBytes(reportMetadataFile.toPath()));
+ String reportFilename = reportName + ".jrxml";
+
+ UriInfo uriInfo = new UriInfoImpl(
+ new URI(""),
+ new URI(""),
+ "",
+ "pgSz=0&filename=" + URLEncoder.encode(reportFilename, StandardCharsets.UTF_8.toString()),
+ Arrays.asList((PathSegment) new PathSegmentImpl("", false))
+ );
+
+ AbstractCommonList list = reportResource.getList(uriInfo);
+
+ if (list.getTotalItems() == 0) {
+ logger.info("Adding report " + reportName);
+
+ try {
+ reportResource.create(resourceMap, null, payload);
+ } catch(Exception e) {
+ logger.error(e.getMessage(), e);
+ }
+ } else {
+ for (ListItem item : list.getListItem()) {
+ String csid = AbstractCommonListUtils.ListItemGetCSID(item);
+
+ // Update an existing report iff:
+ // - it was created autmatically (i.e., by the SPRING_ADMIN user)
+ // - it was last updated automatically (i.e., by the SPRING_ADMIN user)
+ // - it is not soft-deleted
+
+ PoxPayloadOut reportPayload = reportResource.getResourceFromCsid(null, null, csid);
+ PayloadOutputPart corePart = reportPayload.getPart(CollectionSpaceClient.COLLECTIONSPACE_CORE_SCHEMA);
+
+ String createdBy = corePart.asElement().selectSingleNode(CollectionSpaceClient.COLLECTIONSPACE_CORE_CREATED_BY).getText();
+ String updatedBy = corePart.asElement().selectSingleNode(CollectionSpaceClient.COLLECTIONSPACE_CORE_UPDATED_BY).getText();
+ String workflowState = corePart.asElement().selectSingleNode(CollectionSpaceClient.COLLECTIONSPACE_CORE_WORKFLOWSTATE).getText();
+
+ if (
+ createdBy.equals(AuthN.SPRING_ADMIN_USER)
+ && updatedBy.equals(AuthN.SPRING_ADMIN_USER)
+ && !workflowState.equals(WorkflowClient.WORKFLOWSTATE_DELETED)
+ ) {
+ logger.info("Updating report {} with csid {}", reportName, csid);
+
+ try {
+ reportResource.update(resourceMap, null, csid, payload);
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ }
+ } else {
+ logger.info(
+ "Not updating report {} with csid {} - it was not auto-created, or was updated or soft-deleted",
+ reportName, csid);
+ }
+ }
+ }
+ }
}
public void resetElasticSearchIndex() throws Exception {
ElasticSearchComponent es = (ElasticSearchComponent) Framework.getService(ElasticSearchService.class);
for (String repositoryName : es.getRepositoryNames()) {
- logger.log(Level.INFO, String.format("%tc [INFO] Rebuilding Elasticsearch index for repository %s", new Date(), repositoryName));
+ logger.info("Rebuilding Elasticsearch index for repository {}", repositoryName);
es.dropAndInitRepositoryIndex(repositoryName);
}
String repositoryName = ConfigUtils.getRepositoryName(tenantBinding, servicesRepoDomainName);
String docType = NuxeoUtils.getTenantQualifiedDocType(tenantBinding.getId(), serviceBinding.getObject().getName());
- logger.log(Level.INFO, String.format("%tc [INFO] Starting Elasticsearch reindexing for docType %s in repository %s", new Date(), docType, repositoryName));
+ logger.info("Starting Elasticsearch reindexing for docType {} in repository {}", docType, repositoryName);
es.runReindexingWorker(repositoryName, String.format("SELECT ecm:uuid FROM %s", docType));
}
for (TenantBindingType tenantBindings : tenantBindingsTable.values()) {
CSpaceTenant tenant = new CSpaceTenant(tenantBindings.getId(), tenantBindings.getName());
if (shouldInitializeAuthorities(tenant, reset) == true) {
- logger.log(Level.INFO, String.format("Initializing vocabularies and authorities of tenant '%s'.",
- tenant.getId()));
+ logger.info("Initializing vocabularies and authorities of tenant '{}'.", tenant.getId());
for (ServiceBindingType serviceBinding : tenantBindings.getServiceBindings()) {
AuthorityInstanceList element = serviceBinding.getAuthorityInstanceList();
if (element != null && element.getAuthorityInstance() != null) {
try {
initializeAuthorityInstance(resourceMap, authorityInstance, serviceBinding, tenant, reset);
} catch (Exception e) {
- logger.log(Level.SEVERE, "Could not initialize authorities and authority terms: " + e.getMessage());
+ logger.error("Could not initialize authorities and authority terms: " + e.getMessage());
throw e;
}
}
}
if (status == Response.Status.OK.getStatusCode()) {
- logger.log(Level.FINE, String.format("Authority of type '%s' with the short ID of '%s' existed already.",
- serviceName, authorityInstance.getTitleRef()));
+ logger.debug("Authority of type '{}' with the short ID of '{}' existed already.",
+ serviceName, authorityInstance.getTitleRef());
} else if (status == Response.Status.CREATED.getStatusCode()) {
- logger.log(Level.FINE, String.format("Created a new authority of type '%s' with the short ID of '%s'.",
- serviceName, authorityInstance.getTitleRef()));
+ logger.debug("Created a new authority of type '{}' with the short ID of '{}'.",
+ serviceName, authorityInstance.getTitleRef());
} else {
- logger.log(Level.WARNING, String.format("Unknown status '%d' encountered when creating or fetching authority of type '%s' with the short ID of '%s'.",
- serviceName, authorityInstance.getTitleRef()));
+ logger.warn("Unknown status '{}' encountered when creating or fetching authority of type '{}' with the short ID of '{}'.",
+ status, serviceName, authorityInstance.getTitleRef());
}
//
String xmlPayload = client.createAuthorityItemInstance(termShortId, termDisplayName);
try {
authorityResource.createAuthorityItem(resourceMap, null, authoritySpecifier, xmlPayload);
- logger.log(Level.FINE, String.format("Tenant:%s:Created a new term '%s:%s' in the authority of type '%s' with the short ID of '%s'.",
- tenant.getName(), termDisplayName, termShortId, serviceName, authorityInstance.getTitleRef()));
+ logger.debug("Tenant:{}:Created a new term '{}:{}' in the authority of type '{}' with the short ID of '{}'.",
+ tenant.getName(), termDisplayName, termShortId, serviceName, authorityInstance.getTitleRef());
} catch (CSWebApplicationException e) {
response = e.getResponse();
status = response.getStatus();
MultivaluedMap<String, String> queryParams = ctx.getQueryParams();
DocumentHandler handler = createDocumentHandler(ctx);
String docType = queryParams.getFirst(IQueryManager.SEARCH_TYPE_DOCTYPE);
+ String filename = queryParams.getFirst(IQueryManager.SEARCH_TYPE_FILENAME);
List<String> modes = queryParams.get(IQueryManager.SEARCH_TYPE_INVOCATION_MODE);
String whereClause = null;
DocumentFilter documentFilter = null;
documentFilter.appendWhereClause(whereClause, IQueryManager.SEARCH_QUALIFIER_AND);
}
+ if (filename != null && !filename.isEmpty()) {
+ whereClause = QueryManager.createWhereClauseForInvocableByFilename(
+ common_part, filename);
+ documentFilter = handler.getDocumentFilter();
+ documentFilter.appendWhereClause(whereClause, IQueryManager.SEARCH_QUALIFIER_AND);
+ }
+
if (modes != null && !modes.isEmpty()) {
whereClause = QueryManager.createWhereClauseForInvocableByMode(
common_part, modes);
final static String SEARCH_TERM_SEPARATOR = " ";
final static String SEARCH_LIKE = " LIKE ";
final static String SEARCH_ILIKE = " ILIKE ";
- final static String SEARCH_TYPE_KEYWORDS = "keywords";
- final static String SEARCH_TYPE_KEYWORDS_KW = "kw";
- final static String SEARCH_TYPE_KEYWORDS_AS = "as";
- final static String SEARCH_TYPE_PARTIALTERM = "pt";
- final static String SEARCH_TYPE_DOCTYPE = "doctype";
- final static String SEARCH_TYPE_INVOCATION_MODE = "mode";
- final static String SEARCH_TYPE_INVOCATION = "inv";
+ final static String SEARCH_TYPE_KEYWORDS = "keywords";
+ final static String SEARCH_TYPE_KEYWORDS_KW = "kw";
+ final static String SEARCH_TYPE_KEYWORDS_AS = "as";
+ final static String SEARCH_TYPE_PARTIALTERM = "pt";
+ final static String SEARCH_TYPE_DOCTYPE = "doctype";
+ final static String SEARCH_TYPE_FILENAME = "filename";
+ final static String SEARCH_TYPE_INVOCATION_MODE = "mode";
+ final static String SEARCH_TYPE_INVOCATION = "inv";
final static String SEARCH_QUALIFIER_AND = SEARCH_TERM_SEPARATOR + "AND" + SEARCH_TERM_SEPARATOR;
final static String SEARCH_QUALIFIER_OR = SEARCH_TERM_SEPARATOR + "OR" + SEARCH_TERM_SEPARATOR;
- final static String DEFAULT_SELECT_CLAUSE = "SELECT * FROM ";
- final static String CSID_QUERY_PARAM = "csid";
+ final static String DEFAULT_SELECT_CLAUSE = "SELECT * FROM ";
+ final static String CSID_QUERY_PARAM = "csid";
//
*/
public String createWhereClauseForInvocableByDocType(String schema, String docType);
+
+ /**
+ * Creates a filtering where clause from filename, for invocables.
+ *
+ * @param schema the schema name for this invocable
+ * @param docType the filename
+ * @return the where clause
+ */
+ public String createWhereClauseForInvocableByFilename(String schema, String filename);
+
/**
* Creates a filtering where clause from invocation mode, for invocables.
*
<?xml version="1.0" encoding="UTF-8"?>
<tenant:TenantBindingConfig
- xmlns:merge="http://xmlmerge.el4j.elca.ch"
- xmlns:tenant="http://collectionspace.org/services/config/tenant">
+ xmlns:merge="http://xmlmerge.el4j.elca.ch"
+ xmlns:tenant="http://collectionspace.org/services/config/tenant">
- <!-- Add your changes, if any, within the following tag pair. -->
- <!-- The value of the 'id' attribute, below, should match the corresponding -->
- <!-- value in cspace/config/services/tenants/publicart-tenant-bindings-proto.xml -->
+ <!-- Add your changes, if any, within the following tag pair. -->
+ <!-- The value of the 'id' attribute, below, should match the corresponding -->
+ <!-- value in cspace/config/services/tenants/publicart-tenant-bindings-proto.xml -->
- <tenant:tenantBinding id="5000">
- </tenant:tenantBinding>
+ <tenant:tenantBinding id="5000">
+ <tenant:serviceBindings merge:matcher="id" id="Reports">
+ <service:properties xmlns:service="http://collectionspace.org/services/config/service" xmlns:types="http://collectionspace.org/services/config/types">
+ <types:item merge:matcher="skip" merge:action="insert">
+ <types:key>report</types:key>
+ <types:value>obj_current_place_details</types:value>
+ </types:item>
+ <types:item merge:matcher="skip" merge:action="insert">
+ <types:key>report</types:key>
+ <types:value>tombstone_with_budget</types:value>
+ </types:item>
+ </service:properties>
+ </tenant:serviceBindings>
+ </tenant:tenantBinding>
</tenant:TenantBindingConfig>
<service:initHandler xmlns:service="http://collectionspace.org/services/config/service">
<service:classname>org.collectionspace.services.report.nuxeo.ReportPostInitHandler</service:classname>
<service:params>
- <service:property>
- <service:key>readerRoleName</service:key>
- <service:value>reader</service:value>
- </service:property>
+ <service:property>
+ <service:key>readerRoleName</service:key>
+ <service:value>reader</service:value>
+ </service:property>
</service:params>
</service:initHandler>
- <service:properties xmlns:service="http://collectionspace.org/services/config/service">
- <types:item xmlns:types="http://collectionspace.org/services/config/types">
- <types:key>outputMIME</types:key>
- <types:displayName>XML</types:displayName>
- <types:value>application/xml</types:value>
- </types:item>
- <types:item xmlns:types="http://collectionspace.org/services/config/types">
- <types:key>outputMIME</types:key>
- <types:displayName>HTML</types:displayName>
- <types:value>text/html</types:value>
- </types:item>
- <types:item xmlns:types="http://collectionspace.org/services/config/types">
- <types:key>outputMIME</types:key>
- <types:displayName>PDF</types:displayName>
- <types:value>application/pdf</types:value>
- </types:item>
- <types:item xmlns:types="http://collectionspace.org/services/config/types">
- <types:key>outputMIME</types:key>
- <types:value>text/csv</types:value>
- </types:item>
- <types:item xmlns:types="http://collectionspace.org/services/config/types">
- <types:key>outputMIME</types:key>
- <types:value>text/tab-separated-values</types:value>
- </types:item>
- <types:item xmlns:types="http://collectionspace.org/services/config/types">
- <types:key>outputMIME</types:key>
- <types:value>application/msword</types:value>
- </types:item>
- <types:item xmlns:types="http://collectionspace.org/services/config/types">
- <types:key>outputMIME</types:key>
- <types:value>application/vnd.openxmlformats-officedocument.wordprocessingml.document</types:value>
- </types:item>
- <types:item xmlns:types="http://collectionspace.org/services/config/types">
- <types:key>outputMIME</types:key>
- <types:value>application/vnd.ms-excel</types:value>
- </types:item>
- <types:item xmlns:types="http://collectionspace.org/services/config/types">
- <types:key>outputMIME</types:key>
- <types:value>application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</types:value>
- </types:item>
- <types:item xmlns:types="http://collectionspace.org/services/config/types">
- <types:key>outputMIME</types:key>
- <types:value>application/vnd.ms-powerpoint</types:value>
- </types:item>
- <types:item xmlns:types="http://collectionspace.org/services/config/types">
- <types:key>outputMIME</types:key>
- <types:value>application/vnd.openxmlformats-officedocument.presentationml.presentation</types:value>
- </types:item>
- </service:properties>
+ <service:properties xmlns:service="http://collectionspace.org/services/config/service" xmlns:types="http://collectionspace.org/services/config/types">
+ <types:item>
+ <types:key>outputMIME</types:key>
+ <types:displayName>XML</types:displayName>
+ <types:value>application/xml</types:value>
+ </types:item>
+ <types:item>
+ <types:key>outputMIME</types:key>
+ <types:displayName>HTML</types:displayName>
+ <types:value>text/html</types:value>
+ </types:item>
+ <types:item>
+ <types:key>outputMIME</types:key>
+ <types:displayName>PDF</types:displayName>
+ <types:value>application/pdf</types:value>
+ </types:item>
+ <types:item>
+ <types:key>outputMIME</types:key>
+ <types:value>text/csv</types:value>
+ </types:item>
+ <types:item>
+ <types:key>outputMIME</types:key>
+ <types:value>text/tab-separated-values</types:value>
+ </types:item>
+ <types:item>
+ <types:key>outputMIME</types:key>
+ <types:value>application/msword</types:value>
+ </types:item>
+ <types:item>
+ <types:key>outputMIME</types:key>
+ <types:value>application/vnd.openxmlformats-officedocument.wordprocessingml.document</types:value>
+ </types:item>
+ <types:item>
+ <types:key>outputMIME</types:key>
+ <types:value>application/vnd.ms-excel</types:value>
+ </types:item>
+ <types:item>
+ <types:key>outputMIME</types:key>
+ <types:value>application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</types:value>
+ </types:item>
+ <types:item>
+ <types:key>outputMIME</types:key>
+ <types:value>application/vnd.ms-powerpoint</types:value>
+ </types:item>
+ <types:item>
+ <types:key>outputMIME</types:key>
+ <types:value>application/vnd.openxmlformats-officedocument.presentationml.presentation</types:value>
+ </types:item>
+
+ <types:item>
+ <types:key>report</types:key>
+ <types:value>accessions</types:value>
+ </types:item>
+ <types:item>
+ <types:key>report</types:key>
+ <types:value>acq_basic</types:value>
+ </types:item>
+ <types:item>
+ <types:key>report</types:key>
+ <types:value>Acq_List_Basic</types:value>
+ </types:item>
+ <types:item>
+ <types:key>report</types:key>
+ <types:value>box_list</types:value>
+ </types:item>
+ <types:item>
+ <types:key>report</types:key>
+ <types:value>CC_List_Basic</types:value>
+ </types:item>
+ <types:item>
+ <types:key>report</types:key>
+ <types:value>coreAcquisition</types:value>
+ </types:item>
+ <types:item>
+ <types:key>report</types:key>
+ <types:value>coreGroupObject</types:value>
+ </types:item>
+ <types:item>
+ <types:key>report</types:key>
+ <types:value>coreIntake</types:value>
+ </types:item>
+ <types:item>
+ <types:key>report</types:key>
+ <types:value>coreLoanIn</types:value>
+ </types:item>
+ <types:item>
+ <types:key>report</types:key>
+ <types:value>coreLoanOut</types:value>
+ </types:item>
+ <types:item>
+ <types:key>report</types:key>
+ <types:value>coreObjectExit</types:value>
+ </types:item>
+ <types:item>
+ <types:key>report</types:key>
+ <types:value>deaccessions</types:value>
+ </types:item>
+ <types:item>
+ <types:key>report</types:key>
+ <types:value>deed_of_gift</types:value>
+ </types:item>
+ <types:item>
+ <types:key>report</types:key>
+ <types:value>Exhibition_List_Basic</types:value>
+ </types:item>
+ <types:item>
+ <types:key>report</types:key>
+ <types:value>Group_List_Basic</types:value>
+ </types:item>
+ <types:item>
+ <types:key>report</types:key>
+ <types:value>incoming_loan</types:value>
+ </types:item>
+ <types:item>
+ <types:key>report</types:key>
+ <types:value>incoming_loan_letter</types:value>
+ </types:item>
+ <types:item>
+ <types:key>report</types:key>
+ <types:value>LoansIn_List_Basic</types:value>
+ </types:item>
+ <types:item>
+ <types:key>report</types:key>
+ <types:value>LoansOut_List_Basic</types:value>
+ </types:item>
+ <types:item>
+ <types:key>report</types:key>
+ <types:value>obj_computed_location</types:value>
+ </types:item>
+ <types:item>
+ <types:key>report</types:key>
+ <types:value>object_valuation</types:value>
+ </types:item>
+ <types:item>
+ <types:key>report</types:key>
+ <types:value>outgoing_loan_letter</types:value>
+ </types:item>
+ <types:item>
+ <types:key>report</types:key>
+ <types:value>referral</types:value>
+ </types:item>
+ <types:item>
+ <types:key>report</types:key>
+ <types:value>systematicInventory</types:value>
+ </types:item>
+ </service:properties>
<service:object xmlns:service="http://collectionspace.org/services/config/service" name="Report"
version="1.0">
<service:part id="0" control_group="Managed" versionable="true" auditable="false" label="reports-system"
return queryManager.createWhereClauseForInvocableByDocType(schema, docType);
}
+ /**
+ * Creates a filtering where clause from filename, for invocables.
+ *
+ * @param schema the schema name for this invocable
+ * @param docType the filename
+ * @return the where clause
+ */
+ static public String createWhereClauseForInvocableByFilename(String schema, String filename) {
+ return queryManager.createWhereClauseForInvocableByFilename(schema, filename);
+ }
+
/**
* Creates a filtering where clause from invocation mode, for invocables.
*
* @return the string
*/
@Override
- public String createWhereClauseForInvocableByDocType(String schema,
- String docType) {
- String trimmed = (docType == null) ? "" : docType.trim();
+ public String createWhereClauseForInvocableByDocType(String schema, String docType) {
+ String trimmed = sanitizeNXQLString(docType);
+
if (trimmed.isEmpty()) {
throw new RuntimeException("No docType specified.");
}
+
if (schema == null || schema.isEmpty()) {
throw new RuntimeException("No match schema specified.");
}
- String wClause = schema + ":" + InvocableJAXBSchema.FOR_DOC_TYPES
- + " = '" + trimmed + "'";
- return wClause;
+
+ String whereClause = schema + ":" + InvocableJAXBSchema.FOR_DOC_TYPES + " = '" + trimmed + "'";
+
+ return whereClause;
+ }
+
+ /**
+ * Creates a filtering where clause from filename, for invocables.
+ *
+ * @param schema the schema name for this invocable
+ * @param docType the filename
+ * @return the where clause
+ */
+ @Override
+ public String createWhereClauseForInvocableByFilename(String schema, String filename) {
+ String trimmed = sanitizeNXQLString(filename);
+
+ if (trimmed.isEmpty()) {
+ throw new RuntimeException("No filename specified.");
+ }
+
+ if (schema == null || schema.isEmpty()) {
+ throw new RuntimeException("No match schema specified.");
+ }
+
+ String whereClause = schema + ":" + InvocableJAXBSchema.FILENAME + " = '" + trimmed + "'";
+
+ return whereClause;
}
/**
return "";
}
+ private String sanitizeNXQLString(String input) {
+ String trimmed = (input == null) ? "" : input.trim();
+ String escaped = unescapedSingleQuote.matcher(trimmed).replaceAll("\\\\'");
+
+ return escaped;
+ }
+
/**
* @param input
* @return true if there were any chars filtered, that will require a backup
return NuxeoUtils.getByNameWhereClause(csid);
}
-
}
/**
- *
+ *
*/
package org.collectionspace.services.jaxb;
public interface InvocableJAXBSchema {
+ final static String FILENAME = "filename";
final static String FOR_DOC_TYPES = "forDocTypes";
final static String SUPPORTS_SINGLE_DOC = "supportsSingleDoc";
final static String SUPPORTS_DOC_LIST = "supportsDocList";
<arg value="${mvn.opts}" />
</exec>
</target>
-
+
<target name="clean" depends="clean-unix,clean-windows"
description="Delete target directories" >
<delete dir="${build}"/>
<arg value="${mvn.opts}" />
</exec>
</target>
-
- <!--
+
+ <!--
Preserve the legacy name for this target, while noting that
legacy name is no longer descriptive of its purpose.
-->
<target name="deploy_jasper_samples" depends="deploy_report_files" />
<target name="deploy_report_files"
- description="Deploy report files">
+ description="Deploy report files and metadata files">
<copy todir="${jee.server.cspace}/cspace/reports" overwrite="true">
<fileset dir="${basedir}/jasper-cs-report/src/main/resources"
- includes="*.jrxml"/>
+ includes="*.jrxml,*.xml"/>
</copy>
</target>
-
+
<target name="undeploy_report_files"
depends="undeploy_source_report_files,undeploy_compiled_report_files"
description="Undeploy report files">
</target>
-
+
<!-- Removes only the source reports that originated from the source directory. Ones added
manually remain.
-->
<target name="undeploy_source_report_files"
- description="Undeploy source (.jrxml) report files">
+ description="Undeploy source (.jrxml) report files and metadata (.xml) files">
<delete failonerror="false">
- <fileset dir="${jee.server.cspace}/cspace/reports" includes="*.jrxml">
+ <fileset dir="${jee.server.cspace}/cspace/reports" includes="*.jrxml,*.xml">
<present targetdir="${basedir}/jasper-cs-report/src/main/resources" />
</fileset>
</delete>
</target>
-
+
<target name="undeploy_compiled_report_files"
description="Undeploy compiled (.jasper) report files">
<delete failonerror="false">
<target name="deploy" depends="install,deploy_report_files"
description="Deploy report-related artifacts">
<!--
- The following ant call is obsolete. The Nuxeo artifacts are now created
+ The following ant call is obsolete. The Nuxeo artifacts are now created
and deployed using the "csmake" tool.
<ant antfile="nuxeo-platform-cs-report/build.xml" target="deploy" inheritall="false"/>
-->
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<document name="report">
+ <ns2:reports_common xmlns:ns2="http://collectionspace.org/services/report">
+ <name>Acquisition Basic List</name>
+ <notes>Catalog info for objects related to an acquisition record. Runs on a single record only.</notes>
+ <forDocTypes>
+ <forDocType>Acquisition</forDocType>
+ </forDocTypes>
+ <supportsSingleDoc>true</supportsSingleDoc>
+ <supportsDocList>false</supportsDocList>
+ <supportsGroup>false</supportsGroup>
+ <supportsNoContext>false</supportsNoContext>
+ <outputMIME>application/pdf</outputMIME>
+ <filename>Acq_List_Basic.jrxml</filename>
+ </ns2:reports_common>
+</document>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<document name="report">
+ <ns2:reports_common xmlns:ns2="http://collectionspace.org/services/report">
+ <name>Condition Check Basic List</name>
+ <notes>Catalog info for objects related to a condition check record. Runs on a single record only.</notes>
+ <forDocTypes>
+ <forDocType>Conditioncheck</forDocType>
+ </forDocTypes>
+ <supportsSingleDoc>true</supportsSingleDoc>
+ <supportsDocList>false</supportsDocList>
+ <supportsGroup>false</supportsGroup>
+ <supportsNoContext>false</supportsNoContext>
+ <outputMIME>application/pdf</outputMIME>
+ <filename>CC_List_Basic.jrxml</filename>
+ </ns2:reports_common>
+</document>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<document name="report">
+ <ns2:reports_common xmlns:ns2="http://collectionspace.org/services/report">
+ <name>Exhibition Basic List</name>
+ <notes>Catalog info for objects related to a exhibition record. Runs on a single record only.</notes>
+ <forDocTypes>
+ <forDocType>Exhibition</forDocType>
+ </forDocTypes>
+ <supportsSingleDoc>true</supportsSingleDoc>
+ <supportsDocList>false</supportsDocList>
+ <supportsGroup>false</supportsGroup>
+ <supportsNoContext>false</supportsNoContext>
+ <outputMIME>application/pdf</outputMIME>
+ <filename>Exhibition_List_Basic.jrxml</filename>
+ </ns2:reports_common>
+</document>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<document name="report">
+ <ns2:reports_common xmlns:ns2="http://collectionspace.org/services/report">
+ <name>Group Basic List</name>
+ <notes>Catalog info for objects related to a group record. Runs on a group of objects, a single object, or selected objects.</notes>
+ <forDocTypes>
+ <forDocType>CollectionObject</forDocType>
+ </forDocTypes>
+ <supportsSingleDoc>true</supportsSingleDoc>
+ <supportsDocList>true</supportsDocList>
+ <supportsGroup>true</supportsGroup>
+ <supportsNoContext>false</supportsNoContext>
+ <outputMIME>application/pdf</outputMIME>
+ <filename>Group_List_Basic.jrxml</filename>
+ </ns2:reports_common>
+</document>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<document name="report">
+ <ns2:reports_common xmlns:ns2="http://collectionspace.org/services/report">
+ <name>Loan In Basic List</name>
+ <notes>Catalog info for objects related to a loan in record. Runs on a single record only.</notes>
+ <forDocTypes>
+ <forDocType>Loanin</forDocType>
+ </forDocTypes>
+ <supportsSingleDoc>true</supportsSingleDoc>
+ <supportsDocList>false</supportsDocList>
+ <supportsGroup>false</supportsGroup>
+ <supportsNoContext>false</supportsNoContext>
+ <outputMIME>application/pdf</outputMIME>
+ <filename>LoansIn_List_Basic.jrxml</filename>
+ </ns2:reports_common>
+</document>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<document name="report">
+ <ns2:reports_common xmlns:ns2="http://collectionspace.org/services/report">
+ <name>Loan Out Basic List</name>
+ <notes>Catalog info for objects related to a loan out record. Runs on a single record only.</notes>
+ <forDocTypes>
+ <forDocType>Loanout</forDocType>
+ </forDocTypes>
+ <supportsSingleDoc>true</supportsSingleDoc>
+ <supportsDocList>false</supportsDocList>
+ <supportsGroup>false</supportsGroup>
+ <supportsNoContext>false</supportsNoContext>
+ <outputMIME>application/pdf</outputMIME>
+ <filename>LoansOut_List_Basic.jrxml</filename>
+ </ns2:reports_common>
+</document>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<document name="report">
+ <ns2:reports_common xmlns:ns2="http://collectionspace.org/services/report">
+ <name>Acquisition Summary</name>
+ <notes>An acquisition summary report. Runs on a single record only.</notes>
+ <forDocTypes>
+ <forDocType>Acquisition</forDocType>
+ </forDocTypes>
+ <supportsSingleDoc>true</supportsSingleDoc>
+ <supportsDocList>false</supportsDocList>
+ <supportsGroup>false</supportsGroup>
+ <supportsNoContext>false</supportsNoContext>
+ <outputMIME>application/pdf</outputMIME>
+ <filename>acq_basic.jrxml</filename>
+ </ns2:reports_common>
+</document>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<document name="report">
+ <ns2:reports_common xmlns:ns2="http://collectionspace.org/services/report">
+ <name>Acquisition Ethnographic Object List</name>
+ <notes>Core acquisition report. Runs on a single record only.</notes>
+ <forDocTypes>
+ <forDocType>Acquisition</forDocType>
+ </forDocTypes>
+ <supportsSingleDoc>true</supportsSingleDoc>
+ <supportsDocList>false</supportsDocList>
+ <supportsGroup>false</supportsGroup>
+ <supportsNoContext>false</supportsNoContext>
+ <outputMIME>application/pdf</outputMIME>
+ <filename>coreAcquisition.jrxml</filename>
+ </ns2:reports_common>
+</document>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<document name="report">
+ <ns2:reports_common xmlns:ns2="http://collectionspace.org/services/report">
+ <name>Group Object Ethnographic Object List</name>
+ <notes>Core group object report. Runs on a single record only.</notes>
+ <forDocTypes>
+ <forDocType>Group</forDocType>
+ </forDocTypes>
+ <supportsSingleDoc>true</supportsSingleDoc>
+ <supportsDocList>false</supportsDocList>
+ <supportsGroup>false</supportsGroup>
+ <supportsNoContext>false</supportsNoContext>
+ <outputMIME>application/pdf</outputMIME>
+ <filename>coreGroupObject.jrxml</filename>
+ </ns2:reports_common>
+</document>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<document name="report">
+ <ns2:reports_common xmlns:ns2="http://collectionspace.org/services/report">
+ <name>Intake Ethnographic Object List</name>
+ <notes>Core intake report. Runs on a single record only.</notes>
+ <forDocTypes>
+ <forDocType>Intake</forDocType>
+ </forDocTypes>
+ <supportsSingleDoc>true</supportsSingleDoc>
+ <supportsDocList>false</supportsDocList>
+ <supportsGroup>false</supportsGroup>
+ <supportsNoContext>false</supportsNoContext>
+ <outputMIME>application/pdf</outputMIME>
+ <filename>coreIntake.jrxml</filename>
+ </ns2:reports_common>
+</document>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<document name="report">
+ <ns2:reports_common xmlns:ns2="http://collectionspace.org/services/report">
+ <name>Loan In Ethnographic Object List</name>
+ <notes>Core loan in report. Runs on a single record only.</notes>
+ <forDocTypes>
+ <forDocType>Loanin</forDocType>
+ </forDocTypes>
+ <supportsSingleDoc>true</supportsSingleDoc>
+ <supportsDocList>false</supportsDocList>
+ <supportsGroup>false</supportsGroup>
+ <supportsNoContext>false</supportsNoContext>
+ <outputMIME>application/pdf</outputMIME>
+ <filename>coreLoanIn.jrxml</filename>
+ </ns2:reports_common>
+</document>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<document name="report">
+ <ns2:reports_common xmlns:ns2="http://collectionspace.org/services/report">
+ <name>Loan Out Ethnographic Object List</name>
+ <notes>Core loan out report. Runs on a single record only.</notes>
+ <forDocTypes>
+ <forDocType>Loanout</forDocType>
+ </forDocTypes>
+ <supportsSingleDoc>true</supportsSingleDoc>
+ <supportsDocList>false</supportsDocList>
+ <supportsGroup>false</supportsGroup>
+ <supportsNoContext>false</supportsNoContext>
+ <outputMIME>application/pdf</outputMIME>
+ <filename>coreLoanOut.jrxml</filename>
+ </ns2:reports_common>
+</document>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<document name="report">
+ <ns2:reports_common xmlns:ns2="http://collectionspace.org/services/report">
+ <name>Object Exit Ethnographic Object List</name>
+ <notes>Core object exit report. Runs on a single record only.</notes>
+ <forDocTypes>
+ <forDocType>ObjectExit</forDocType>
+ </forDocTypes>
+ <supportsSingleDoc>true</supportsSingleDoc>
+ <supportsDocList>false</supportsDocList>
+ <supportsGroup>false</supportsGroup>
+ <supportsNoContext>false</supportsNoContext>
+ <outputMIME>application/pdf</outputMIME>
+ <filename>coreObjectExit.jrxml</filename>
+ </ns2:reports_common>
+</document>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<document name="report">
+ <ns2:reports_common xmlns:ns2="http://collectionspace.org/services/report">
+ <name>Object Valuation</name>
+ <notes>Returns latest valuation information for selected objects. Runs on selected objects, or all objects.</notes>
+ <forDocTypes>
+ <forDocType>CollectionObject</forDocType>
+ </forDocTypes>
+ <supportsSingleDoc>false</supportsSingleDoc>
+ <supportsDocList>true</supportsDocList>
+ <supportsGroup>false</supportsGroup>
+ <supportsNoContext>true</supportsNoContext>
+ <outputMIME>application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</outputMIME>
+ <filename>object_valuation.jrxml</filename>
+ </ns2:reports_common>
+</document>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<document name="report">
+ <ns2:reports_common xmlns:ns2="http://collectionspace.org/services/report">
+ <name>Systematic Inventory</name>
+ <notes>Generate a checklist for performing an inventory on a range of storage locations. Runs on all records, using the provided start and end locations.</notes>
+ <forDocTypes>
+ <forDocType>Locationitem</forDocType>
+ </forDocTypes>
+ <supportsSingleDoc>false</supportsSingleDoc>
+ <supportsDocList>false</supportsDocList>
+ <supportsGroup>false</supportsGroup>
+ <supportsNoContext>true</supportsNoContext>
+ <outputMIME>application/pdf</outputMIME>
+ <filename>systematicInventory.jrxml</filename>
+ </ns2:reports_common>
+</document>
-/**
+/**
* ReportClient.java
*
* {Purpose of This Class}
* FIXME: http://issues.collectionspace.org/browse/CSPACE-1684
*/
public class ReportClient extends AbstractCommonListPoxServiceClientImpl<ReportProxy, ReportsCommon> {
-
- public static final String SERVICE_NAME = "reports";
- public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME;
- public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT;
+ public static final String SERVICE_NAME = "reports";
+ public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME;
+ public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT;
public static final String SERVICE_COMMON_PART_NAME = SERVICE_NAME + PART_LABEL_SEPARATOR + PART_COMMON_LABEL;
- public static final String PDF_MIME_TYPE = "application/pdf";
- public static final String CSV_MIME_TYPE = "text/csv";
- public static final String TSV_MIME_TYPE = "text/tab-separated-values";
- public static final String MSWORD_MIME_TYPE = "application/msword";
- public static final String OPEN_DOCX_MIME_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
- public static final String MSEXCEL_MIME_TYPE = "application/vnd.ms-excel";
- public static final String OPEN_XLSX_MIME_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
- public static final String MSPPT_MIME_TYPE = "application/vnd.ms-powerpoint";
- public static final String OPEN_PPTX_MIME_TYPE = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
- public static final String DEFAULT_REPORT_OUTPUT_MIME = PDF_MIME_TYPE;
- public static final String COMPILED_REPORT_EXTENSION = ".jasper";
- public static final String REPORT_DECSRIPTION_EXTENSION = ".jrxml";
+ public static final String PDF_MIME_TYPE = "application/pdf";
+ public static final String CSV_MIME_TYPE = "text/csv";
+ public static final String TSV_MIME_TYPE = "text/tab-separated-values";
+ public static final String MSWORD_MIME_TYPE = "application/msword";
+ public static final String OPEN_DOCX_MIME_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
+ public static final String MSEXCEL_MIME_TYPE = "application/vnd.ms-excel";
+ public static final String OPEN_XLSX_MIME_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
+ public static final String MSPPT_MIME_TYPE = "application/vnd.ms-powerpoint";
+ public static final String OPEN_PPTX_MIME_TYPE = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
+ public static final String DEFAULT_REPORT_OUTPUT_MIME = PDF_MIME_TYPE;
+ public static final String COMPILED_REPORT_EXTENSION = ".jasper";
+ public static final String REPORT_DECSRIPTION_EXTENSION = ".jrxml";
+ public static final String REPORT_METADATA_EXTENSION = ".xml";
- public ReportClient() throws Exception {
+ public ReportClient() throws Exception {
super();
}
- public ReportClient(String clientPropertiesFilename) throws Exception {
+ public ReportClient(String clientPropertiesFilename) throws Exception {
super(clientPropertiesFilename);
}
@Override
- public String getServiceName() {
- return SERVICE_NAME;
- }
+ public String getServiceName() {
+ return SERVICE_NAME;
+ }
- @Override
+ @Override
public String getServicePathComponent() {
- return SERVICE_PATH_COMPONENT;
- }
+ return SERVICE_PATH_COMPONENT;
+ }
@Override
public Class<ReportProxy> getProxyClass() {
return ReportProxy.class;
}
-
+
/*
* Proxied service calls
*/
-
- /**
- * @return
- * @see org.collectionspace.services.client.ReportProxy#getReport()
- */
- public Response readListFiltered(
- String docType, String mode) {
- return getProxy().readListFiltered(docType, mode);
- }
-
- public Response publishReport(String csid,
- InvocationContext invContext) {
- return getProxy().publishReport(csid, invContext);
- }
-
+
+ /**
+ * @return
+ * @see org.collectionspace.services.client.ReportProxy#getReport()
+ */
+ public Response readListFiltered(String docType, String mode) {
+ return getProxy().readListFiltered(docType, mode);
+ }
+
+ public Response publishReport(String csid, InvocationContext invContext) {
+ return getProxy().publishReport(csid, invContext);
+ }
}
*/
package org.collectionspace.services.report;
+import java.io.File;
import java.io.InputStream;
import java.util.List;
import org.collectionspace.services.common.CSWebApplicationException;
import org.collectionspace.services.common.NuxeoBasedResource;
import org.collectionspace.services.common.ResourceMap;
+import org.collectionspace.services.common.ServiceMain;
import org.collectionspace.services.common.ServiceMessages;
+import org.collectionspace.services.common.api.JEEServerDeployment;
import org.collectionspace.services.common.context.ServiceContext;
import org.collectionspace.services.common.document.DocumentFilter;
import org.collectionspace.services.common.document.DocumentHandler;
public class ReportResource extends NuxeoBasedResource {
final Logger logger = LoggerFactory.getLogger(ReportResource.class);
+ private static String REPORTS_FOLDER = "reports";
+
@Override
protected String getVersionString() {
final String lastChangeRevision = "$LastChangedRevision: 1982 $";
MultivaluedMap<String, String> queryParams = ctx.getQueryParams();
DocumentHandler handler = createDocumentHandler(ctx);
String docType = queryParams.getFirst(IQueryManager.SEARCH_TYPE_DOCTYPE);
+ String filename = queryParams.getFirst(IQueryManager.SEARCH_TYPE_FILENAME);
List<String> modes = queryParams.get(IQueryManager.SEARCH_TYPE_INVOCATION_MODE);
String whereClause = null;
DocumentFilter documentFilter = null;
documentFilter = handler.getDocumentFilter();
documentFilter.appendWhereClause(whereClause, IQueryManager.SEARCH_QUALIFIER_AND);
}
+ if (filename != null && !filename.isEmpty()) {
+ whereClause = QueryManager.createWhereClauseForInvocableByFilename(
+ common_part, filename);
+ documentFilter = handler.getDocumentFilter();
+ documentFilter.appendWhereClause(whereClause, IQueryManager.SEARCH_QUALIFIER_AND);
+ }
if (modes != null && !modes.isEmpty()) {
whereClause = QueryManager.createWhereClauseForInvocableByMode(
common_part, modes);
return result;
}
+ private static String getReportBasePath() {
+ return (
+ ServiceMain.getInstance().getServerRootDir() +
+ File.separator +
+ JEEServerDeployment.CSPACE_DIR_NAME +
+ File.separator +
+ REPORTS_FOLDER +
+ File.separator
+ );
+ }
+
+ public static File getReportSourceFile(String reportName) {
+ return new File(
+ getReportBasePath() + reportName + ReportClient.REPORT_DECSRIPTION_EXTENSION);
+ }
+
+ public static File getReportCompiledFile(String reportName) {
+ return new File(
+ getReportBasePath() + reportName + ReportClient.COMPILED_REPORT_EXTENSION);
+ }
+
+ public static File getReportMetadataFile(String reportName) {
+ return new File(
+ getReportBasePath() + reportName + ReportClient.REPORT_METADATA_EXTENSION);
+ }
}
import org.collectionspace.services.report.ReportsCommon.ForRoles;
import org.collectionspace.services.report.MIMEType;
import org.collectionspace.services.report.MIMETypeItemType;
+import org.collectionspace.services.report.ReportResource;
import org.collectionspace.services.report.ReportsCommon;
import org.collectionspace.services.report.ReportsOuputMimeList;
import org.collectionspace.services.client.PoxPayloadIn;
private final Logger logger = LoggerFactory.getLogger(ReportDocumentModelHandler.class);
private static final Pattern INVALID_CSID_PATTERN = Pattern.compile("[^\\w\\-]");
- private static String REPORTS_FOLDER = "reports";
private static String CSID_LIST_SEPARATOR = ",";
private static String REPORTS_STD_CSID_PARAM = "csid";
}
- private InputStream buildReportResult(String reportCSID,
- HashMap<String, Object> params, String reportFileName, String outputMimeType, StringBuffer outReportFileName)
- throws Exception {
- Connection conn = null;
- InputStream result = null;
+ private InputStream buildReportResult(
+ String reportCSID,
+ HashMap<String, Object> params,
+ String reportFileName,
+ String outputMimeType,
+ StringBuffer outReportFileName
+ ) throws Exception {
+
+ Connection conn = null;
+ InputStream result = null;
try {
- String fileNameBase = Tools.getFilenameBase(reportFileName);
- String compiledReportFilename = fileNameBase+ReportClient.COMPILED_REPORT_EXTENSION;
- String reportDescriptionFilename = fileNameBase+ReportClient.REPORT_DECSRIPTION_EXTENSION;
-
- String basePath = ServiceMain.getInstance().getServerRootDir() +
- File.separator + JEEServerDeployment.CSPACE_DIR_NAME +
- File.separator + REPORTS_FOLDER +
- // File.separator + tenantName +
- File.separator; // + reportFileName;
-
- String compiledFilePath = basePath+compiledReportFilename;
- File f = new File(compiledFilePath);
- if(!f.exists()) { // Need to compile the file
- // First verify that there is a source file.
- String sourceFilePath = basePath+reportDescriptionFilename;
- File f2 = new File(sourceFilePath);
- if(!f2.exists()) { // Missing source file - error!
- logger.error("Report for csid={} is missing the specified source file: {}",
- reportCSID, sourceFilePath);
- throw new RuntimeException("Report is missing the specified source file!");
- }
+ String reportName = Tools.getFilenameBase(reportFileName);
+ File reportCompiledFile = ReportResource.getReportCompiledFile(reportName);
- logger.info("Report for csid={} is not compiled. Compiling first, and saving to: {}",
- reportCSID, compiledFilePath);
+ if (!reportCompiledFile.exists()) {
+ // Need to compile the file.
- JasperDesign design = JRXmlLoader.load(sourceFilePath);
+ File reportSourceFile = ReportResource.getReportSourceFile(reportName);
- design.setScriptletClass("org.collectionspace.services.report.jasperreports.CSpaceReportScriptlet");
+ if(!reportSourceFile.exists()) {
+ logger.error("Report for csid={} is missing source file: {}",
+ reportCSID, reportSourceFile.getAbsolutePath());
- JasperCompileManager.compileReportToFile(design, compiledFilePath);
- }
+ throw new RuntimeException("Report is missing source file");
+ }
- conn = getConnection();
+ logger.info("Report for csid={} is not compiled. Compiling first, and saving to: {}",
+ reportCSID, reportCompiledFile.getAbsolutePath());
- if (logger.isTraceEnabled()) {
- logger.trace("ReportResource for csid=" + reportCSID
- +" output as "+outputMimeType+" using report file: "+compiledFilePath);
- }
- FileInputStream fileStream = new FileInputStream(compiledFilePath);
+ JasperDesign design = JRXmlLoader.load(reportSourceFile.getAbsolutePath());
+
+ design.setScriptletClass("org.collectionspace.services.report.jasperreports.CSpaceReportScriptlet");
+
+ JasperCompileManager.compileReportToFile(design, reportCompiledFile.getAbsolutePath());
+ }
+
+ conn = getConnection();
+
+ if (logger.isTraceEnabled()) {
+ logger.trace("ReportResource for csid=" + reportCSID
+ + " output as " + outputMimeType + " using report file: " + reportCompiledFile.getAbsolutePath());
+ }
+
+ FileInputStream fileStream = new FileInputStream(reportCompiledFile);
// export report to pdf and build a response with the bytes
//JasperExportManager.exportReportToPdf(jasperprint);