Note |
---|
Timetracker version 4.7.5 or higher is required to access this API |
Note |
---|
Wage manager permission required for the user this service |
A cost rate with a date can be added to a user via this service.
API
Code Block |
---|
package org.everit.jira.reporting.service.costrate;
import java.time.LocalDate;
import java.util.List;
/**
* Public User Cost Service.
*/
public interface UserCostService {
/**
* Add cost rate. Requires Wage Manager permission.
*
* @param userKey
* the user key
* @param validFromIncl
* the from date (inclusive).
* @param costRate
* the cost rate.
*/
void addCostRate(String userKey, LocalDate validFromIncl, double costRate);
/**
* Delete cost rate. Requires Wage Manager permission.
*
* @param costRateId
* the id of cost rate.
*/
void deleteCostRate(long costRateId);
/**
* List all cost rates for the specific users. Requires Wage Manager permission, else returns an empty list.
*
* @param userKey
* the user key.
* @return list of cost rates.
*/
List<CostRateInfo> listCostRates(String userKey);
/**
* Update cost rate. Requires Wage Manager permission.
*
* @param costRateId
* the id of cost rate.
* @param userKey
* the user key
* @param validFromIncl
* the from date (inclusive).
* @param costRate
* the cost rate.
*/
void updateCostRate(long costRateId, String userKey, LocalDate validFromIncl, double costRate);
} |
Example
Code Block |
---|
import com.onresolve.scriptrunner.runner.customisers.PluginModule;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import com.onresolve.scriptrunner.runner.customisers.WithPlugin;
import org.everit.jira.reporting.service.costrate.CostRateInfo;
import org.everit.jira.reporting.service.costrate.UserCostService;
import java.util.Arrays;
@WithPlugin("org.everit.jira.timetracker.plugin")
@PluginModule
UserCostService userCostService;
// list cost rates for a user.
List<CostRateInfo> costRates = userCostService.listCostRates("douglas.arnold@everit.biz");
// log.info(costRates);
// add cost rate for a user
LocalDate now = LocalDate.now();
userCostService.addCostRate("douglas.arnold@everit.biz", now, (double) 5.0);
costRates = userCostService.listCostRates("douglas.arnold@everit.biz");
// log.info(costRates);
// update cost rate (change cost rate for a user)
CostRateInfo costRateInfo = costRates.get(0);
userCostService.updateCostRate(costRateInfo.costRateId, costRateInfo.userKey, costRateInfo.validFromIncl, (double) 2.0);
costRates = userCostService.listCostRates("douglas.arnold@everit.biz");
// log.info(costRates);
// update cost rate (change cost rate and from date for a user)
LocalDate nowMinusTenDays = LocalDate.now()
.minus(10, ChronoUnit.DAYS);
costRateInfo = costRates.get(0);
userCostService.updateCostRate(costRateInfo.costRateId, costRateInfo.userKey, nowMinusTenDays, (double) 1.0);
costRates = userCostService.listCostRates("douglas.arnold@everit.biz");
// log.info(costRates);
// delete cost rate
costRateInfo = costRates.get(0);
userCostService.deleteCostRate(costRateInfo.costRateId);
costRates = userCostService.listCostRates("douglas.arnold@everit.biz");
// log.info(costRates); |