package net.sourceforge.fenixedu.domain.softwareLicenseManagement; import java.util.ArrayList; import java.util.List; import net.sourceforge.fenixedu.domain.Person; import net.sourceforge.fenixedu.domain.RootDomainObject; import net.sourceforge.fenixedu.domain.exceptions.DomainException; import net.sourceforge.fenixedu.injectionCode.AccessControl; import pt.ist.fenixWebFramework.services.Service; public class SoftwareApplication extends SoftwareApplication_Base { private SoftwareApplication(String name, String vendor, String vendorEmail, String versionIdentifier, String repositoryUrl, String serialNumber, String licenseMessage, LicenseModel model) { super(); setName(name); setVendor(vendor); setVendorEmail(vendorEmail); setRootDomainObject(RootDomainObject.getInstance()); newVersion(versionIdentifier, repositoryUrl, serialNumber, licenseMessage, model); } @Service public SoftwareVersion newVersion(String versionIdentifier, String repositoryUrl, String serialNumber, String licenseMessage, LicenseModel model) { return new SoftwareVersion(this, versionIdentifier, repositoryUrl, serialNumber, licenseMessage, model); } @Service public static SoftwareApplication create(String name, String vendor, String vendorEmail, String versionIdentifier, String repositoryUrl, String serialNumber, String licenseMessage, LicenseModel model) { return new SoftwareApplication(name, vendor, vendorEmail, versionIdentifier, repositoryUrl, serialNumber, licenseMessage, model); } public boolean isPersonAbleToRequestLicense(Person person) { for (SoftwareVersion version : getVersions()) { if (version.isPersonAbleToRequestLicense(person)) { return !isPersonWithActiveRequestedLicense(person); } } return false; } public boolean isPersonWithActiveRequestedLicense(Person person) { for (SoftwareVersion version : getVersions()) { if (version.hasActiveRequestForPerson(person)) { return true; } } return false; } public boolean isCurrentPersonAbleToRequestLicense() { return isPersonAbleToRequestLicense(AccessControl.getPerson()); } public int getAvailableVersionCountFor(Person person) { int counter = 0; for (SoftwareVersion version : getVersions()) { if (version.isPersonAbleToRequestLicense(person)) { counter++; } } return counter; } public List getAvailableVersionsFor(Person person) { List versions = new ArrayList(); for (SoftwareVersion version : getVersions()) { if (version.isPersonAbleToRequestLicense(person)) { versions.add(version); } } return versions; } public List getAvailableVersionsForCurrentUser() { return getAvailableVersionsFor(AccessControl.getPerson()); } public void delete() { if (!getVersions().isEmpty()) { throw new DomainException("error.operator.softwareLicenseManagement.application.cannotDeleteApplicationWithVersions"); } removeRootDomainObject(); super.deleteDomainObject(); } }