use of org.wso2.carbon.apimgt.api.model.MonetizationUsagePublishInfo in project carbon-apimgt by wso2.
the class MonetizationApiServiceImpl method monetizationPublishUsageStatusGet.
/**
* Retrieves the status of the last monetization usage publishing job
*
* @return Retruns the status of the last monetization usage publishing jon
*/
@Override
public Response monetizationPublishUsageStatusGet(MessageContext messageContext) {
MonetizationUsagePublishInfo monetizationUsagePublishInfo;
try {
APIAdmin apiAdmin = new APIAdminImpl();
monetizationUsagePublishInfo = apiAdmin.getMonetizationUsagePublishInfo();
return Response.ok().entity(MonetizationAPIMappinUtil.fromUsageStateToDTO(monetizationUsagePublishInfo)).build();
} catch (APIManagementException ex) {
RestApiUtil.handleInternalServerError("Could not derive monetization usage publish info", ex, log);
}
return null;
}
use of org.wso2.carbon.apimgt.api.model.MonetizationUsagePublishInfo in project carbon-apimgt by wso2.
the class DefaultMonetizationImpl method publishMonetizationUsageRecords.
/**
* Update info about monetization usage publish job
*
* @param monetizationUsagePublishInfo
* @return boolean always return true if there is no exception
* @throws MonetizationException
*/
@Override
public boolean publishMonetizationUsageRecords(MonetizationUsagePublishInfo monetizationUsagePublishInfo) throws MonetizationException {
APIAdmin apiAdmin = new APIAdminImpl();
monetizationUsagePublishInfo.setState(APIConstants.Monetization.COMPLETED);
monetizationUsagePublishInfo.setStatus(APIConstants.Monetization.SUCCESSFULL);
DateFormat df = new SimpleDateFormat(APIConstants.Monetization.USAGE_PUBLISH_TIME_FORMAT);
Date dateobj = new Date();
// get the time in UTC format
df.setTimeZone(TimeZone.getTimeZone(APIConstants.Monetization.USAGE_PUBLISH_TIME_ZONE));
String currentDate = df.format(dateobj);
long currentTimestamp = apiAdmin.getTimestamp(currentDate);
monetizationUsagePublishInfo.setLastPublishTime(currentTimestamp);
try {
apiAdmin.updateMonetizationUsagePublishInfo(monetizationUsagePublishInfo);
} catch (APIManagementException e) {
throw new MonetizationException("Failed to update the monetization usage publish info", e);
}
return true;
}
use of org.wso2.carbon.apimgt.api.model.MonetizationUsagePublishInfo in project carbon-apimgt by wso2.
the class MonetizationUsagePublishAgent method run.
@Override
public void run() {
Monetization monetizationImpl = null;
APIAdmin apiAdmin = null;
try {
apiAdmin = new APIAdminImpl();
monetizationImpl = apiAdmin.getMonetizationImplClass();
monetizationUsagePublishInfo.setState(APIConstants.Monetization.RUNNING);
monetizationUsagePublishInfo.setStatus(APIConstants.Monetization.INPROGRESS);
DateFormat df = new SimpleDateFormat(APIConstants.Monetization.USAGE_PUBLISH_TIME_FORMAT);
Date dateobj = new Date();
df.setTimeZone(TimeZone.getTimeZone(APIConstants.Monetization.USAGE_PUBLISH_TIME_ZONE));
String currentDate = df.format(dateobj);
long currentTimestamp = apiAdmin.getTimestamp(currentDate);
// set the current time as starting time of the job
monetizationUsagePublishInfo.setStartedTime(currentTimestamp);
apiAdmin.updateMonetizationUsagePublishInfo(monetizationUsagePublishInfo);
monetizationImpl.publishMonetizationUsageRecords(monetizationUsagePublishInfo);
} catch (Exception e) {
try {
// update the state and status of the job incase of any execptions
monetizationUsagePublishInfo.setState(APIConstants.Monetization.COMPLETED);
monetizationUsagePublishInfo.setStatus(APIConstants.Monetization.FAILED);
apiAdmin.updateMonetizationUsagePublishInfo(monetizationUsagePublishInfo);
} catch (APIManagementException ex) {
String errorMsg = "Failed to update the state of monetization ussge publisher";
log.error(errorMsg, ex);
}
String errorMsg = "Failed to publish monetization usage to billing Engine";
log.error(errorMsg, e);
}
}
use of org.wso2.carbon.apimgt.api.model.MonetizationUsagePublishInfo in project carbon-apimgt by wso2.
the class ApiMgtDAO method getMonetizationUsagePublishInfo.
/**
* Derives info about monetization usage publish job
*
* @return ifno about the monetization usage publish job
* @throws APIManagementException
*/
public MonetizationUsagePublishInfo getMonetizationUsagePublishInfo() throws APIManagementException {
Connection conn = null;
ResultSet rs = null;
PreparedStatement ps = null;
try {
conn = APIMgtDBUtil.getConnection();
String query = SQLConstants.GET_MONETIZATION_USAGE_PUBLISH_INFO;
ps = conn.prepareStatement(query);
rs = ps.executeQuery();
if (rs.next()) {
MonetizationUsagePublishInfo monetizationUsagePublishInfo = new MonetizationUsagePublishInfo();
monetizationUsagePublishInfo.setId(rs.getString("ID"));
monetizationUsagePublishInfo.setState(rs.getString("STATE"));
monetizationUsagePublishInfo.setStatus(rs.getString("STATUS"));
monetizationUsagePublishInfo.setStartedTime(rs.getLong("STARTED_TIME"));
monetizationUsagePublishInfo.setLastPublishTime(rs.getLong("PUBLISHED_TIME"));
return monetizationUsagePublishInfo;
}
} catch (SQLException e) {
handleException("Error while retrieving Monetization Usage Publish Info: ", e);
} finally {
APIMgtDBUtil.closeAllConnections(ps, conn, rs);
}
return null;
}
use of org.wso2.carbon.apimgt.api.model.MonetizationUsagePublishInfo in project carbon-apimgt by wso2.
the class MonetizationAPIMappinUtil method fromUsageStateToDTO.
/**
* Set the info of monetization usage publisher to DTO of the monetization usage status
*
* @param info info about the monetization usage publisher job
* @return the DTO for monetization usage publish status
*/
public static MonetizationUsagePublishInfoDTO fromUsageStateToDTO(MonetizationUsagePublishInfo info) {
MonetizationUsagePublishInfoDTO monetizationUsagePublishInfo = new MonetizationUsagePublishInfoDTO();
monetizationUsagePublishInfo.setState(info.getState());
monetizationUsagePublishInfo.setStatus(info.getStatus());
monetizationUsagePublishInfo.setStartedTime(Long.toString(info.getStartedTime()));
monetizationUsagePublishInfo.setLastPublsihedTime(Long.toString(info.getLastPublishTime()));
return monetizationUsagePublishInfo;
}
Aggregations