Before getting started, ensure that:
import de.hybris.platform.tx.Transaction
import de.hybris.platform.tx.TransactionBody
import de.hybris.platform.core.Registry
import de.hybris.platform.core.TenantAwareThreadFactory
import de.hybris.platform.commerceservices.impersonation.ImpersonationService
import de.hybris.platform.commerceservices.impersonation.ImpersonationContext
import de.hybris.platform.servicelayer.search.FlexibleSearchQuery
import java.text.SimpleDateFormat
import java.util.Date;
import org.codehaus.groovy.runtime.*;
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit;
/*******************************/
/** Core **/
/*******************************/
def getBean(String name) {
return spring.getBean(name)
}
/**
* Builder class to execute closure in Transaction.
*/
class TransactionExecutor {
/**
* Build an TransactionExecutor.
*/
TransactionExecutor() {}
/**
* Execute the specified closure in a transaction.
*/
def execute(Closure execution) {
def currentTx = Transaction.current()
return currentTx.execute(new TransactionBody() {
public Object execute() throws Exception {
return execution()
}
})
}
}
TransactionExecutor.metaClass.getBean = {name ->
spring.getBean(name)
}
flexibleSearchService = spring.getBean("flexibleSearchService")
modelService = spring.getBean("modelService")
def date = new Date()
sdf = new SimpleDateFormat("yyyy-MM-dd")
currentDate = sdf.format(date)
def query = "select {sp:pk} " + "from { " + "SubscriptionPricePlan as sp }"+
"where {sp:startTime} <= ?startTime and {sp:endTime} >= ?endTime";
def params = [startTime: currentDate, endTime: currentDate]
def subscriptionPricePlanList = flexibleSearchService.search(query,params).result
print "Current Date : " + currentDate + "\n"
def executorService = Executors.newFixedThreadPool(10, new TenantAwareThreadFactory(Registry.getCurrentTenant()))
try {
if(subscriptionPricePlanList != null){
subscriptionPricePlanList.each {entry ->
if (sdf.format(entry.getStartTime()) <= currentDate && currentDate <= sdf.format(entry.getEndTime())) {
entry.getOneTimeChargeEntries().each {oneTime ->
if (oneTime.getSubscriptionBillingId() == null) {
print "Start Time :" + sdf.format(entry.getStartTime())
print " \t End Time :" + sdf.format(entry.getEndTime())
print " Removing" + entry.getPricePlanId()
print "\n"
executorService.execute(new Runnable() {
public void run() {
def transactionExecutor = new TransactionExecutor()
transactionExecutor.execute() {
modelService.removeAll(entry)
}
}
})
}
}
}
}
}
} finally {
executorService.shutdown()
executorService.awaitTermination(1, TimeUnit.HOURS)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
8 | |
3 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 |