Skip to content

Commit

Permalink
Merge pull request #973 from sheiksalahudeen/develop
Browse files Browse the repository at this point in the history
Fixed Issues
  • Loading branch information
sheiksalahudeen authored Jan 30, 2017
2 parents de7e0a5 + 03c545a commit 920ccfc
Show file tree
Hide file tree
Showing 15 changed files with 121 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.kuali.ole.OLEConstants;
import org.kuali.ole.constants.OleNGConstants;
import org.kuali.ole.deliver.service.ParameterValueResolver;
import org.kuali.ole.oleng.batch.process.model.BatchProcessJob;
import org.kuali.ole.oleng.dao.DescribeDAO;
import org.kuali.ole.oleng.scheduler.job.BatchSchedulerJob;
import org.kuali.ole.oleng.util.OleNGSchedulerHelperUtil;
import org.kuali.ole.spring.batch.processor.*;
import org.kuali.ole.utility.OleHttpRestGet;
import org.kuali.ole.utility.OleHttpRestGetImpl;
import org.kuali.rice.krad.UserSession;
import org.kuali.rice.krad.util.GlobalVariables;
import org.quartz.*;
import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.impl.StdSchedulerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.text.ParseException;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -56,6 +58,9 @@ public class OleNGBatchJobScheduler extends OleNGSchedulerHelperUtil {

public void initializeAllJobs() {
LOG.info("-- initializing batch jobs --");

String defaultUserForRestCall = getDefaultUserForRestCall();

List<BatchProcessJob> batchProcessJobs = getDescribeDAO().fetchAllBatchProcessJobs();
if(CollectionUtils.isNotEmpty(batchProcessJobs)) {
for (Iterator<BatchProcessJob> iterator = batchProcessJobs.iterator(); iterator.hasNext(); ) {
Expand All @@ -72,7 +77,7 @@ public void initializeAllJobs() {
batchProcessJob.setNextRunTime(new Timestamp(nextValidTimeAfter.getTime()));
batchProcessJob.setJobType(OleNGConstants.SCHEDULED);
getBusinessObjectService().save(batchProcessJob);
scheduleOrRescheduleJob(id, profileId, type, cron);
scheduleOrRescheduleJob(id, profileId, type, cron, defaultUserForRestCall);
}
}
} catch (Exception e) {
Expand All @@ -83,19 +88,14 @@ public void initializeAllJobs() {
}
}

public void scheduleOrRescheduleJob(long id, long profileId, String jobType, String cron) {
public void scheduleOrRescheduleJob(long id, long profileId, String jobType, String cron, String principalName) {
try {
String jobId = OleNGConstants.JOB_NAME_PFX + id;
JobDetail jobDetail = getScheduler().getJobDetail(jobId, OleNGConstants.GROUP);
String triggerName = jobId + OleNGConstants.TRIGGER_SFX;
if(null != jobDetail) {
unScheduleJob(jobId, false);
}
String principalName = "";
UserSession userSession = GlobalVariables.getUserSession();
if(userSession != null) {
principalName = userSession.getPrincipalName();
}
getScheduler().start();
JobDetail job = getJobDetail(jobType, jobId, OleNGConstants.GROUP);

Expand Down Expand Up @@ -217,4 +217,9 @@ public DescribeDAO getDescribeDAO() {
public void setDescribeDAO(DescribeDAO describeDAO) {
this.describeDAO = describeDAO;
}

private String getDefaultUserForRestCall() {
return ParameterValueResolver.getInstance().getParameter(OLEConstants
.APPL_ID_OLE, OLEConstants.DLVR_NMSPC, OLEConstants.DLVR_CMPNT, OleNGConstants.DEFAULT_USER_FOR_REST_CALLS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ private void overlayBibProfile(OleTxRecord oleTxRecord, Record marcRecord, Strin
overlayDonor(oleTxRecord, dataMapping);
overlayItemType(oleTxRecord, dataMapping);
overlayItemStatus(oleTxRecord, dataMapping);
overlayCopyNumber(oleTxRecord, dataMapping);
overlayEnumeration(oleTxRecord, dataMapping);
}
} else {
Expand Down Expand Up @@ -168,17 +167,6 @@ private void overlayEnumeration(OleTxRecord oleTxRecord, JSONObject dataMapping)
}
}

private void overlayCopyNumber(OleTxRecord oleTxRecord, JSONObject dataMapping) {
JSONArray jsonArrayeFromJsonObject = getBatchUtil().getJSONArrayeFromJsonObject(dataMapping, OleNGConstants.BatchProcess.COPY_NUMBER);
if (null != jsonArrayeFromJsonObject) {
List<String> listFromJSONArray = getBatchUtil().getListFromJSONArray(jsonArrayeFromJsonObject.toString());
if(CollectionUtils.isNotEmpty(listFromJSONArray)) {
String copyNumber = listFromJSONArray.get(0);
oleTxRecord.setSingleCopyNumber(copyNumber);
}
}
}

private void overlayLocation(OleTxRecord oleTxRecord, JSONObject dataMapping, Exchange exchange) {
StringBuilder locationName = new StringBuilder();
LocationUtil locationUtil = getOleNGMemorizeService().getLocationUtil();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public boolean validateOleOrderRecord(OleOrderRecord oleOrderRecord, Exchange ex
valid = validateListPrice(oleTxRecord, exchange, recordIndex) && valid;
valid = validateFundingSource(oleTxRecord, exchange, recordIndex) && valid;
valid = validateDonorCode(oleTxRecord, exchange, recordIndex) && valid;
valid = validateSingleCopyNumber(oleTxRecord, exchange, recordIndex) && valid;

valid = validateBibRecord(oleOrderRecord, exchange, recordIndex) && valid;

Expand Down Expand Up @@ -455,6 +456,19 @@ private boolean validateDonorCode(OleTxRecord oleTxRecord, Exchange exchange, In
return true;
}


private boolean validateSingleCopyNumber(OleTxRecord oleTxRecord, Exchange exchange, Integer recordIndex) {
String singleCopyNumber = oleTxRecord.getSingleCopyNumber();
if (StringUtils.isNotBlank(singleCopyNumber)) {
if(!NumberUtils.isDigits(singleCopyNumber)) {
getBatchUtil().addOrderFaiureResponseToExchange(
new ValidationException("Invalid Single Copy Number Value : " + singleCopyNumber), recordIndex, exchange);
return false;
}
}
return true;
}

private void validateVendorCustomerNumber(OleTxRecord oleTxRecord, Exchange exchange, Integer recordIndex) {
String vendorInfoCustomer = oleTxRecord.getVendorInfoCustomer();
if (StringUtils.isNotBlank(vendorInfoCustomer)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.kuali.ole.scheduler;

import org.apache.log4j.Logger;
import org.kuali.ole.oleng.scheduler.OleNGBatchJobScheduler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

/**
* Created by sheiks on 27/01/17.
*/
@Component
public class SchedulerListener implements ApplicationListener<ContextRefreshedEvent> {

private static final Logger LOG = Logger.getLogger(SchedulerListener.class);

@Autowired
private OleNGBatchJobScheduler oleNGBatchJobScheduler;

public void onApplicationEvent(final ContextRefreshedEvent event) {
ApplicationContext ctx = event.getApplicationContext();
LOG.info("SchedulerListener is started to schedule the jobs.");
oleNGBatchJobScheduler.initializeAllJobs();
LOG.info("SchedulerListener is ended");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -670,16 +670,17 @@ private void performUpdateForPODocuments(String poNumber, BibTree bibTree, Strin
*/
public Item setItemDetails(OleCopy oleCopy, String itemTypeDescription) {
Item item = null;
boolean newItem = false;
org.kuali.ole.docstore.common.document.Item itemDocument = (org.kuali.ole.docstore.common.document.Item) getDataCarrierService().getData("reqItemId:" + oleCopy.getReqItemId() + ":item");
if(null != itemDocument) {
String content = itemDocument.getContent();
if(StringUtils.isNotBlank(content)) {
item = (Item) new ItemOleml().deserializeContent(content);
}
}

if(item == null) {
item = new Item();
newItem = true;
}
/*
* Location itemLocation = new Location(); LocationLevel locationLevel = new LocationLevel(); String locationLevelCode =
Expand All @@ -693,7 +694,9 @@ public Item setItemDetails(OleCopy oleCopy, String itemTypeDescription) {
docstoreItemType.setFullValue(itemTypeDescription);
item.setItemType(docstoreItemType);
item.setEnumeration(oleCopy.getEnumeration());
item.setCopyNumber(oleCopy.getCopyNumber());
if(newItem) {
item.setCopyNumber(oleCopy.getCopyNumber());
}
return item;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.kuali.ole.spring.batch.BatchUtil;
import org.kuali.ole.spring.batch.processor.*;
import org.kuali.rice.core.api.config.property.ConfigContext;
import org.kuali.rice.krad.UserSession;
import org.kuali.rice.krad.util.GlobalVariables;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
Expand Down Expand Up @@ -270,7 +271,12 @@ public String scheduleJob(@RequestParam("jobId") String jobId, @RequestParam("nu
matchedBatchJob.setNextRunTime(null != date ? new Timestamp(date.getTime()) : null);
matchedBatchJob.setJobType(OleNGConstants.SCHEDULED);
getBusinessObjectService().save(matchedBatchJob);
oleNGBatchJobScheduler.scheduleOrRescheduleJob(Long.valueOf(jobId), matchedBatchJob.getBatchProfileId(), matchedBatchJob.getProfileType(), matchedBatchJob.getCronExpression());
String principalName = "";
UserSession userSession = GlobalVariables.getUserSession();
if(userSession != null) {
principalName = userSession.getPrincipalName();
}
oleNGBatchJobScheduler.scheduleOrRescheduleJob(Long.valueOf(jobId), matchedBatchJob.getBatchProfileId(), matchedBatchJob.getProfileType(), matchedBatchJob.getCronExpression(), principalName);
jsonObject.put(OleNGConstants.JOB_ID, matchedBatchJob.getJobId());
jsonObject.put(OleNGConstants.JOB_TYPE, matchedBatchJob.getJobType());
jsonObject.put(OleNGConstants.CRON_EXPRESSION, matchedBatchJob.getCronExpression());
Expand Down
1 change: 1 addition & 0 deletions ole-app/olefs/src/main/webapp/WEB-INF/rest-servlet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<context:component-scan base-package="org.kuali.ole.describe.rest"/>
<context:component-scan base-package="org.kuali.ole.oleng"/>
<context:component-scan base-package="org.kuali.ole.spring.batch"/>
<context:component-scan base-package="org.kuali.ole.scheduler"/>

<bean id="circulationRestService" class="org.kuali.ole.ncip.service.impl.CirculationRestServiceImpl"/>
<bean id="gobiAPIService" class="org.kuali.ole.gobi.service.impl.GobiAPIServiceImpl"/>
Expand Down
13 changes: 0 additions & 13 deletions ole-app/olefs/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -545,18 +545,5 @@ This file contains custom application specific web.xml content.
<url-pattern>/api/*</url-pattern>
</servlet-mapping>

<servlet>
<display-name>BatchSchedulerServlet</display-name>
<servlet-name>OleBatchJobScheduler</servlet-name>
<servlet-class>org.kuali.ole.oleng.servlet.BatchSchedulerServlet</servlet-class>
<!-- startup after the rest servlet defined above -->
<load-on-startup>8</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>OleBatchJobScheduler</servlet-name>
<url-pattern>/scheduleJobs/*</url-pattern>
</servlet-mapping>

</web-app>

Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ var orderFields = [
{id: 'vendorProfileCode', name: 'Vendor Profile Code'},
{id: 'vendorItemIdentifier', name: 'Vendor Item Identifier'},
{id: 'volumeNumber', name: 'Volume Number'},
{id: 'Single Copy Number', name: 'singleCopyNumber'}
{id: 'singleCopyNumber', name: 'Single Copy Number'}
];

var discountTypes = [
Expand Down
1 change: 1 addition & 0 deletions ole-app/olefs/src/main/webapp/batchProcessJobs.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<script src="framework/angular/js/ui-bootstrap-tpls-0.14.3.js"></script>
<script src="batchScheduling/scripts/date.js"></script>
<script src="framework/jquery/js/jquery-ui.js"></script>
<script src="oleng/js/ole-app-filter.js"></script>
<link rel="stylesheet" href="framework/jquery/css/jquery-ui.css"/>
<!--<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/angular_material/1.0.0/angular-material.min.css">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-animate.min.js"></script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
var batchProcessJobsApp = angular.module('batchProcessJobs', ['datatables', 'customDirectives', 'ui.date']);
var batchProcessJobsApp = angular.module('batchProcessJobs', [
'ui.bootstrap',
'datatables', 'customDirectives', 'ui.date',
'ole.app-filter'
]);

var jobTypes = [
{id: 'adhoc', name: 'Adhoc'},
Expand Down Expand Up @@ -45,7 +49,9 @@ function enableDatePicker(){
batchProcessJobsApp.controller('batchProcessJobsController', ['$scope', '$http', '$interval', 'DTOptionsBuilder', function ($scope, $http, $interval, DTOptionsBuilder) {



$scope.currentPage = 1;
$scope.rowsToShow = [10,25, 50, 75, 100];
$scope.pageSize = 10;

for (var i = 1; i <= 31; i++) {
monthDays.push({id: i,name: i});
Expand All @@ -62,6 +68,7 @@ batchProcessJobsApp.controller('batchProcessJobsController', ['$scope', '$http',

$scope.quickLaunch = {
outputFormats: BATCH_CONSTANTS.OUTPUT_FORMATS,

outputFormat: 'Marc'
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
<div class="container col-lg-12">
<div>
<div class="form-group">
<table id="jobExecutionTableId" datatable="ng" dt-options="dtOptions" class="table table-bordered row-border hover">

<div class="form-group">
<label>Show
<select ng-model="pageSize">
<option ng-repeat="row in rowsToShow">{{row}}</option>
</select> entries
</label>
<ul uib-pagination class="pull-right" previous-text="< Prev" next-text="Next >" total-items="batchJobs.length"
ng-model="currentPage" items-per-page="pageSize" max-size="5" boundary-links="true"></ul>
</div>

<table id="jobExecutionTableId" class="table table-bordered row-border hover">
<thead style="height: 20px">
<tr>
<th>Job Detail Id</th>
Expand All @@ -23,7 +34,7 @@
</tr>
</thead>
<tbody>
<tr ng-repeat="batchJob in batchJobs">
<tr ng-repeat="batchJob in batchJobs | orderBy:'-jobDetailId' | paginate:currentPage:pageSize">
<td><span ng-bind="batchJob.jobDetailId"></span></td>
<td><span ng-bind="batchJob.jobName"></span></td>
<td><span ng-bind="batchJob.jobId"></span></td>
Expand Down Expand Up @@ -53,6 +64,14 @@
</tr>
</tbody>
</table>

<div class="form-group">
<div ng-show="batchJobs.length > 0">
Showing {{((currentPage - 1)*pageSize) + 1}} to {{currentPage * pageSize > batchJobs.length ? batchJobs.length : currentPage * pageSize}} from {{batchJobs.length}}
<ul uib-pagination class="pull-right" previous-text="< Prev" next-text="Next >" total-items="batchJobs.length"
ng-model="currentPage" items-per-page="pageSize" max-size="5" boundary-links="true"></ul>
</div>
</div>
</div>
</div>

Expand Down
13 changes: 13 additions & 0 deletions ole-app/olefs/src/main/webapp/oleng/js/ole-app-filter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Created by sheiks on 15/01/17.
*/
angular.module('ole.app-filter', [])
.filter('paginate', function () {
return function (arr, currentPage, pageSize) {
try {
return arr.slice((currentPage - 1)*pageSize, currentPage * pageSize);
} catch(err) {
return arr;
}
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ public void testSchedule() {
@Test
public void testReschedule() {
OleNGBatchJobScheduler oleNGBatchJobScheduler = new OleNGBatchJobScheduler();
oleNGBatchJobScheduler.scheduleOrRescheduleJob(1,2,"", "0/5 * * * * ?");
oleNGBatchJobScheduler.scheduleOrRescheduleJob(1,2,"", "1/5 * * * * ?");
oleNGBatchJobScheduler.scheduleOrRescheduleJob(1,2,"", "3/5 * * * * ?");
oleNGBatchJobScheduler.scheduleOrRescheduleJob(1,2,"", "0/5 * * * * ?","ole-quickstart");
oleNGBatchJobScheduler.scheduleOrRescheduleJob(1,2,"", "1/5 * * * * ?","ole-quickstart");
oleNGBatchJobScheduler.scheduleOrRescheduleJob(1,2,"", "3/5 * * * * ?","ole-quickstart");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static final class BatchProcess {

public static final String REQUISITION_SOURCE = "requisitionSource";
public static final String ITEM_PRICE_SOURCE = "itemPriceSource";
public static final String SINGLE_COPY_NUMBER = "singleCopyNumber";
public static final String SINGLE_COPY_NUMBER = "Single Copy Number";


public static final String DESTINATION_FIELD_ITEM_HOLDINGS_CALL_NUMBER = "Holdings Call Number";
Expand Down

0 comments on commit 920ccfc

Please sign in to comment.