package eu.smartlm.abs.portal.data.aggregation;
import java.util.Set;
import org.gridforum.x2003.urWg.HostDocument.Host;
import org.gridforum.x2003.urWg.ProjectNameDocument.ProjectName;
import org.gridforum.x2003.urWg.SubmitHostDocument.SubmitHost;
import org.gridforum.x2003.urWg.UserIdentityDocument.UserIdentity;
import eu.smartlm.abs.portal.view.portlet.QueryPortlet;
import eu.smartlm.schemas.x2009.x06.urec.LicenseResourceType;
import eu.smartlm.schemas.x2009.x06.urec.ProductType;
import eu.smartlm.schemas.x2009.x06.urec.SmartLMUsageRecordType;
/**
* This class does all the necessary agggregations of Usage Records to be shown in a graph.
* @author David García Pérez - CESGA
*/
public class DataAggregation {
/**
* This method returns the number of hours or money a user has used an specific application
* @param usageRecords Sets of usage record where to perform the calculation
* @param user User that used the application
* @param application application to determine the number of usage hours
* @param type defines if it is an accounting or billing query
* @return the number of hours or money that this application was used by this specific user in this concrete list of usage records
*/
public static double determineUsageByProduct(Set<SmartLMUsageRecordType> usageRecords, UserIdentity user, ProductType product, String type) {
double amount = 0.0;
for(SmartLMUsageRecordType usageRecord : usageRecords) {
if(usageRecord.getUserIdentityArray(0).getLocalUserId().equals(user.getLocalUserId())) {
LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
for(int i = 0; i < licenseResources.length; i++) {
LicenseResourceType licenseResource = licenseResources[i];
if(licenseResource.getLicense().getProduct().getProductId().equals(product.getProductId())) {
if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
amount = amount + TimeCalculation.timeDifferenceInHours(
licenseResource.getAccountingPeriod().getStartTime(),
licenseResource.getAccountingPeriod().getEndTime());
else
amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
}
}
}
}
return amount;
}
/**
* Determines the usage hours or money for an specific product
* @param usageRecords Usage records where to calculate the usage of the product
* @param product product from which the usage is going to be calculated
* @param type accounting or billing
* @return number of hour or money used for this product
*/
public static double determineUsageForAProduct(Set<SmartLMUsageRecordType> usageRecords, ProductType product, String type) {
double amount = 0.0;
for(SmartLMUsageRecordType usageRecord : usageRecords) {
LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
for(int i = 0; i < licenseResources.length; i++) {
LicenseResourceType licenseResource = licenseResources[i];
if(licenseResource.getLicense().getProduct().getProductId().equals(product.getProductId())) {
if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
amount = amount + TimeCalculation.timeDifferenceInHours(
licenseResource.getAccountingPeriod().getStartTime(),
licenseResource.getAccountingPeriod().getEndTime());
else
amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
}
}
}
return amount;
}
/**
* This method returns the number of hours or money of a user has used for an specific host machine
* @param usageRecords Usage Records from where to extract the hours usage
* @param user User from where to extract the usage hours
* @param host Host to see how much was used by the users
* @param type accounting or billing
* @return the number of hours or money that this host was used by the user.
*/
public static double determineUsageByHost(Set<SmartLMUsageRecordType> usageRecords, UserIdentity user, Host host, String type) {
double amount = 0.0;
for(SmartLMUsageRecordType usageRecord : usageRecords) {
if(usageRecord.getUserIdentityArray(0).getLocalUserId().equals(user.getLocalUserId())) {
Host[] hosts = usageRecord.getHostArray();
for(int j = 0; j < hosts.length; j++) {
if(hosts[j].getStringValue().equals(host.getStringValue())) {
LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
for(int i = 0; i < licenseResources.length; i++) {
LicenseResourceType licenseResource = licenseResources[i];
if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
amount = amount + TimeCalculation.timeDifferenceInHours(
licenseResource.getAccountingPeriod().getStartTime(),
licenseResource.getAccountingPeriod().getEndTime());
else
amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
}
}
}
}
}
return amount;
}
/**
* This method returns the number of hours or money of a user has used for an specific SubmitHost machine
* @param usageRecords Usage Records from where to extract the hours usage
* @param user User from where to extract the usage hours
* @param submitHost SubmitHost to see how much was used by the users
* @param type accounting or billing
* @return the number of hours or money that this submitHost was used by the user.
*/
public static double determineUsageBySubmitHost(Set<SmartLMUsageRecordType> usageRecords, UserIdentity user, SubmitHost submitHost, String type) {
double amount = 0.0;
for(SmartLMUsageRecordType usageRecord : usageRecords) {
if(usageRecord.getUserIdentityArray(0).getLocalUserId().equals(user.getLocalUserId())) {
SubmitHost[] submitHosts = usageRecord.getSubmitHostArray();
for(int j = 0; j < submitHosts.length; j++) {
if(submitHosts[j].getStringValue().equals(submitHost.getStringValue())) {
LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
for(int i = 0; i < licenseResources.length; i++) {
LicenseResourceType licenseResource = licenseResources[i];
if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
amount = amount + TimeCalculation.timeDifferenceInHours(
licenseResource.getAccountingPeriod().getStartTime(),
licenseResource.getAccountingPeriod().getEndTime());
else
amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
}
}
}
}
}
return amount;
}
/**
* Calculates the amount of hours or money used by a USER.
* @param usageRecords list of usage records from where to calculate this
* @param user user that we want to know the amount of usage
* @param type accounting or billing
* @return the number of usage hours or money
*/
public static double determineUsageForAUser(Set<SmartLMUsageRecordType> usageRecords, UserIdentity user, String type) {
double amount = 0.0;
for(SmartLMUsageRecordType usageRecord : usageRecords) {
if(usageRecord.getUserIdentityArray(0).getLocalUserId().equals(user.getLocalUserId())) {
LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
for(int i = 0; i < licenseResources.length; i++) {
LicenseResourceType licenseResource = licenseResources[i];
if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
amount = amount + TimeCalculation.timeDifferenceInHours(
licenseResource.getAccountingPeriod().getStartTime(),
licenseResource.getAccountingPeriod().getEndTime());
else
amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
}
}
}
return amount;
}
/**
* Calculates the amount of hours or money used by a Department.
* @param usageRecords list of usage records from where to calculate this
* @param accountingGroup accountingGroup that we want to know the amount of usage
* @param accounting or billing
* @return the number of usage hours or money
*/
public static double determineUsageForAnAccountingGroup(Set<SmartLMUsageRecordType> usageRecords, String accountingGroup, String type) {
double amount = 0.0;
for(SmartLMUsageRecordType usageRecord : usageRecords) {
LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
for(int i = 0; i < licenseResources.length; i++) {
LicenseResourceType licenseResource = licenseResources[i];
if(licenseResource.getAccountingGroup().equals(accountingGroup)) {
if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
amount = amount + TimeCalculation.timeDifferenceInHours(
licenseResource.getAccountingPeriod().getStartTime(),
licenseResource.getAccountingPeriod().getEndTime());
else
amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
}
}
}
return amount;
}
/**
* Calculates the amount of hours or money used by a Project.
* @param usageRecords list of usage records from where to calculate this
* @param project project that we want to know the amount of usage
* @param accounting or billing
* @return the number of usage hours or money
*/
public static double determineUsageForAProject(Set<SmartLMUsageRecordType> usageRecords, ProjectName project, String type) {
double amount = 0.0;
for(SmartLMUsageRecordType usageRecord : usageRecords) {
ProjectName[] projects = usageRecord.getProjectNameArray();
for(int i = 0; i < projects.length; i++) {
ProjectName projectInUsageRecord = projects[i];
if(projectInUsageRecord.getStringValue().equals(project.getStringValue())) {
LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
for(int j = 0; j < licenseResources.length; j++) {
LicenseResourceType licenseResource = licenseResources[j];
if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
amount = amount + TimeCalculation.timeDifferenceInHours(
licenseResource.getAccountingPeriod().getStartTime(),
licenseResource.getAccountingPeriod().getEndTime());
else
amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
}
}
}
}
return amount;
}
/**
* Calculates the amount of hours or money used by a user filtered by a Project.
* @param usageRecords list of usage records from where to calculate this
* @param user user that we want to know the amount of usage
* @param project project that we want to know the amount of usage
* @param accounting or billing
* @return the number of usage hours or money
*/
public static double determineUsageByProject(Set<SmartLMUsageRecordType> usageRecords, UserIdentity user, ProjectName project, String type) {
double amount = 0.0;
for(SmartLMUsageRecordType usageRecord : usageRecords) {
if(usageRecord.getUserIdentityArray(0).getLocalUserId().equals(user.getLocalUserId())) {
ProjectName[] projects = usageRecord.getProjectNameArray();
for(int i = 0; i < projects.length; i++) {
ProjectName projectInUsageRecord = projects[i];
if(projectInUsageRecord.getStringValue().equals(project.getStringValue())) {
LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
for(int j = 0; j < licenseResources.length; j++) {
LicenseResourceType licenseResource = licenseResources[j];
if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
amount = amount + TimeCalculation.timeDifferenceInHours(
licenseResource.getAccountingPeriod().getStartTime(),
licenseResource.getAccountingPeriod().getEndTime());
else
amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
}
}
}
}
}
return amount;
}
/**
* Calculates the amount of hours or money used by a Product filtered by an AccountingGroup
* @param usageRecords Usage Records where to do the search
* @param product Product for where to calculate the hours
* @param accountingGroup AccountingGroup for where to calculate the hours
* @return the number of hours or money
*/
public static double determineUsageForProductByAccountingGroup(Set<SmartLMUsageRecordType> usageRecords, ProductType product, String accountingGroup, String type) {
double amount = 0.0;
for(SmartLMUsageRecordType usageRecord : usageRecords) {
LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
for(int i = 0; i < licenseResources.length; i++) {
LicenseResourceType licenseResource = licenseResources[i];
if(licenseResource.getAccountingGroup().equals(accountingGroup) &&
licenseResource.getLicense().getProduct().getProductId().equals(product.getProductId())) {
if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
amount = amount + TimeCalculation.timeDifferenceInHours(
licenseResource.getAccountingPeriod().getStartTime(),
licenseResource.getAccountingPeriod().getEndTime());
else
amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
}
}
}
return amount;
}
/**
* Calculates the amount of hours or money used by a Product and filtered by a Host
* @param usageRecords Usage Records with the usage information
* @param product Product for where to calculate the usage hours
* @param host To filter the usage hours
* @param type accounting or billing
* @return the usage hours or money
*/
public static double determineUsageByProductFilterByHost(Set<SmartLMUsageRecordType> usageRecords, ProductType product, Host host, String type) {
double amount = 0.0;
for(SmartLMUsageRecordType usageRecord : usageRecords) {
Host[] hosts = usageRecord.getHostArray();
for(int j = 0; j < hosts.length; j++) {
if(hosts[j].getStringValue().equals(host.getStringValue())) {
LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
for(int i = 0; i < licenseResources.length; i++) {
LicenseResourceType licenseResource = licenseResources[i];
if(licenseResource.getLicense().getProduct().getProductId().equals(product.getProductId())) {
if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
amount = amount + TimeCalculation.timeDifferenceInHours(
licenseResource.getAccountingPeriod().getStartTime(),
licenseResource.getAccountingPeriod().getEndTime());
else
amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
}
}
}
}
}
return amount;
}
/**
* Calculates the amount of hours or money used by a Product and filtered by a SubmitHost
* @param usageRecords Usage records with the usage information
* @param product Product from where to calculate the usage records
* @param submitHost to filter the hours
* @param type accounting or billing
* @return the usage hours or money
*/
public static double determineUsageByProductFilterBySubmitHost(
Set<SmartLMUsageRecordType> usageRecords,
ProductType product,
SubmitHost submitHost,
String type) {
double amount = 0.0;
for(SmartLMUsageRecordType usageRecord : usageRecords) {
SubmitHost[] submitHosts = usageRecord.getSubmitHostArray();
for(int j = 0; j < submitHosts.length; j++) {
if(submitHosts[j].getStringValue().equals(submitHost.getStringValue())) {
LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
for(int i = 0; i < licenseResources.length; i++) {
LicenseResourceType licenseResource = licenseResources[i];
if(licenseResource.getLicense().getProduct().getProductId().equals(product.getProductId())) {
if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
amount = amount + TimeCalculation.timeDifferenceInHours(
licenseResource.getAccountingPeriod().getStartTime(),
licenseResource.getAccountingPeriod().getEndTime());
else
amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
}
}
}
}
}
return amount;
}
/**
* Calculates the amount of hours or money used by an User filtered by an AccountingGroup
* @param usageRecords Usage Records where to do the search
* @param product Product for where to calculate the hours
* @param accountingGroup AccountingGroup for where to calculate the hours
* @param type accounting or billing
* @return the number of hours or money
*/
public static double determineUsageByAccountingGroup(Set<SmartLMUsageRecordType> usageRecords, UserIdentity user, String accountingGroup, String type) {
double amount = 0.0;
for(SmartLMUsageRecordType usageRecord : usageRecords) {
if(usageRecord.getUserIdentityArray(0).getLocalUserId().equals(user.getLocalUserId())) {
LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
for(int i = 0; i < licenseResources.length; i++) {
LicenseResourceType licenseResource = licenseResources[i];
if(licenseResource.getAccountingGroup().equals(accountingGroup)) {
if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
amount = amount + TimeCalculation.timeDifferenceInHours(
licenseResource.getAccountingPeriod().getStartTime(),
licenseResource.getAccountingPeriod().getEndTime());
else
amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
}
}
}
}
return amount;
}
/**
* Calculates the amount of hours or money used by an AccountingGroup filter by a Project
* @param usageRecords usage records that contains the usage information
* @param accountingGroup interested accounting group
* @param project interested project to use as a filter
* @param type accounting or billing
* @return the number of usage hours or money
*/
public static double determineUsageForAnAccountingGroupFilterByProject(
Set<SmartLMUsageRecordType> usageRecords,
String accountingGroup,
ProjectName project,
String type) {
double amount = 0.0;
for(SmartLMUsageRecordType usageRecord : usageRecords) {
ProjectName[] projects = usageRecord.getProjectNameArray();
for(int j = 0; j < projects.length; j++) {
if(projects[j].getStringValue().equals(project.getStringValue())) {
LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
for(int i = 0; i < licenseResources.length; i++) {
LicenseResourceType licenseResource = licenseResources[i];
if(licenseResource.getAccountingGroup().equals(accountingGroup)) {
if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
amount = amount + TimeCalculation.timeDifferenceInHours(
licenseResource.getAccountingPeriod().getStartTime(),
licenseResource.getAccountingPeriod().getEndTime());
else
amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
}
}
}
}
}
return amount;
}
/**
* Calculates the amount of hours or money used by an Product and Filter by a Project
* @param usageRecords Usage Records where to do the search
* @param product Product for where to calculate the hours
* @param project AccountingGRoups for where to calculate the hours
* @param type accounting or billing
* @return the number of hours or money
*/
public static double determineUsageByProductFilterByProject(Set<SmartLMUsageRecordType> usageRecords, ProductType product, ProjectName project, String type) {
double amount = 0.0;
for(SmartLMUsageRecordType usageRecord : usageRecords) {
ProjectName[] projects = usageRecord.getProjectNameArray();
for(int j = 0; j < projects.length; j++) {
if(projects[j].getStringValue().equals(project.getStringValue())) {
LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
for(int i = 0; i < licenseResources.length; i++) {
LicenseResourceType licenseResource = licenseResources[i];
if(licenseResource.getLicense().getProduct().getProductId().equals(product.getProductId())) {
if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
amount = amount + TimeCalculation.timeDifferenceInHours(
licenseResource.getAccountingPeriod().getStartTime(),
licenseResource.getAccountingPeriod().getEndTime());
else
amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
}
}
}
}
}
return amount;
}
/**
* Calculates the amount of hours or money used by an AccountingGroup Filter by a Host
* @param usageRecords
* @param accountingGroup
* @param host
* @param type
* @return
*/
public static double determineUsageByAccountingGroupFilterByHost(Set<SmartLMUsageRecordType> usageRecords, String accountingGroup, Host host, String type) {
double amount = 0.0;
for(SmartLMUsageRecordType usageRecord : usageRecords) {
Host[] hosts = usageRecord.getHostArray();
for(int j = 0; j < hosts.length; j++) {
if(hosts[j].getStringValue().equals(host.getStringValue())) {
LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
for(int i = 0; i < licenseResources.length; i++) {
LicenseResourceType licenseResource = licenseResources[i];
if(licenseResource.getAccountingGroup().equals(accountingGroup)) {
if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
amount = amount + TimeCalculation.timeDifferenceInHours(
licenseResource.getAccountingPeriod().getStartTime(),
licenseResource.getAccountingPeriod().getEndTime());
else
amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
}
}
}
}
}
return amount;
}
/**
* Calculates the amount of hours or money used by an AccountingGroup Filter by a SubmitHost
* @param usageRecords
* @param accountingGroup
* @param submitHost
* @param type
* @return
*/
public static double determineUsageByAccountingGroupFilterBySubmitHost(
Set<SmartLMUsageRecordType> usageRecords,
String accountingGroup,
SubmitHost submitHost,
String type) {
double amount = 0.0;
for(SmartLMUsageRecordType usageRecord : usageRecords) {
SubmitHost[] submitHosts = usageRecord.getSubmitHostArray();
for(int j = 0; j < submitHosts.length; j++) {
if(submitHosts[j].getStringValue().equals(submitHost.getStringValue())) {
LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
for(int i = 0; i < licenseResources.length; i++) {
LicenseResourceType licenseResource = licenseResources[i];
if(licenseResource.getAccountingGroup().equals(accountingGroup)) {
if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
amount = amount + TimeCalculation.timeDifferenceInHours(
licenseResource.getAccountingPeriod().getStartTime(),
licenseResource.getAccountingPeriod().getEndTime());
else
amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
}
}
}
}
}
return amount;
}
/**
* Calculates the amount of hours or money used by a Project Filter by a Host
* @param usageRecords
* @param project
* @param host
* @param type
* @return the number of hours
*/
public static double determineUsageByProjectFilterByHost(
Set<SmartLMUsageRecordType> usageRecords,
ProjectName project,
Host host,
String type) {
double amount = 0.0;
for(SmartLMUsageRecordType usageRecord : usageRecords) {
ProjectName[] projects = usageRecord.getProjectNameArray();
for(int i = 0; i < projects.length; i++) {
if(projects[i].getStringValue().equals(project.getStringValue())) {
Host[] hosts = usageRecord.getHostArray();
for(int j = 0; j < hosts.length; j++) {
if(hosts[j].getStringValue().equals(host.getStringValue())) {
LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
for(int z = 0; z < licenseResources.length; z++) {
LicenseResourceType licenseResource = licenseResources[z];
if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
amount = amount + TimeCalculation.timeDifferenceInHours(
licenseResource.getAccountingPeriod().getStartTime(),
licenseResource.getAccountingPeriod().getEndTime());
else
amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
}
}
}
}
}
}
return amount;
}
/**
* Calculates the amount of hours or money used by a Project Filter by a SubmitHost
* @param usageRecords
* @param project
* @param host
* @param type
* @return the number of hours or money
*/
public static double determineUsageByProjectFilterBySubmitHost(
Set<SmartLMUsageRecordType> usageRecords,
ProjectName project,
SubmitHost submitHost,
String type) {
double amount = 0.0;
for(SmartLMUsageRecordType usageRecord : usageRecords) {
ProjectName[] projects = usageRecord.getProjectNameArray();
for(int i = 0; i < projects.length; i++) {
if(projects[i].getStringValue().equals(project.getStringValue())) {
SubmitHost[] submitHosts = usageRecord.getSubmitHostArray();
for(int j = 0; j < submitHosts.length; j++) {
if(submitHosts[j].getStringValue().equals(submitHost.getStringValue())) {
LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
for(int z = 0; z < licenseResources.length; z++) {
LicenseResourceType licenseResource = licenseResources[z];
if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
amount = amount + TimeCalculation.timeDifferenceInHours(
licenseResource.getAccountingPeriod().getStartTime(),
licenseResource.getAccountingPeriod().getEndTime());
else
amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
}
}
}
}
}
}
return amount;
}
/**
* Calculates the amount of hours or money used by a Host
* @param usageRecords
* @param host
* @param type
* @return
*/
public static double determineUsageForAHost(Set<SmartLMUsageRecordType> usageRecords, Host host, String type) {
double amount = 0.0;
for(SmartLMUsageRecordType usageRecord : usageRecords) {
Host[] hosts = usageRecord.getHostArray();
for(int j = 0; j < hosts.length; j++) {
if(hosts[j].getStringValue().equals(host.getStringValue())) {
LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
for(int z = 0; z < licenseResources.length; z++) {
LicenseResourceType licenseResource = licenseResources[z];
if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
amount = amount + TimeCalculation.timeDifferenceInHours(
licenseResource.getAccountingPeriod().getStartTime(),
licenseResource.getAccountingPeriod().getEndTime());
else
amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
}
}
}
}
return amount;
}
/**
* Calculates the amount of hours or money used by a SubmitHost
* @param usageRecords
* @param submitHost
* @param type
* @return
*/
public static double determineUsageForASubmitHost(Set<SmartLMUsageRecordType> usageRecords, SubmitHost submitHost, String type) {
double amount = 0.0;
for(SmartLMUsageRecordType usageRecord : usageRecords) {
SubmitHost[] submitHosts = usageRecord.getSubmitHostArray();
for(int j = 0; j < submitHosts.length; j++) {
if(submitHosts[j].getStringValue().equals(submitHost.getStringValue())) {
LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
for(int z = 0; z < licenseResources.length; z++) {
LicenseResourceType licenseResource = licenseResources[z];
if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
amount = amount + TimeCalculation.timeDifferenceInHours(
licenseResource.getAccountingPeriod().getStartTime(),
licenseResource.getAccountingPeriod().getEndTime());
else
amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
}
}
}
}
return amount;
}
}