
net.customware.license.atlassian.ao.manager.impl.ActiveObjectsLicenseManager Maven / Gradle / Ivy
The newest version!
package net.customware.license.atlassian.ao.manager.impl;
import com.atlassian.activeobjects.external.ActiveObjects;
import net.customware.license.atlassian.ao.bean.License;
import net.customware.license.atlassian.ao.manager.LicenseManager;
import net.java.ao.DBParam;
import net.java.ao.Query;
import org.apache.commons.lang.StringUtils;
public class ActiveObjectsLicenseManager implements LicenseManager {
protected final ActiveObjects ao;
public ActiveObjectsLicenseManager(ActiveObjects ao) {
this.ao = ao;
}
public License installLicense(String refId, String content) {
if (StringUtils.isEmpty(content)) {
return null;
}
License license = getLicense(refId);
if (license != null) {
license.setContent(content);
license.save();
return license;
} else {
DBParam[] params = new DBParam[]{
new DBParam("CONTENT", content),
new DBParam("REF_ID", refId)
};
return ao.create(License.class, params);
}
}
public License getLicense(String refId) {
if (StringUtils.isEmpty(refId)) {
return null;
}
String queryString = "REF_ID = ?";
Query query = Query.select().where(queryString, refId);
License[] results = ao.find(License.class, query);
if (results != null && results.length > 0) {
return results[0];
}
return null;
}
public void uninstallLicense(String refId) {
License license = getLicense(refId);
if (license != null) {
ao.delete(license);
}
}
public License installLicense(String license) {
return installLicense("", license);
}
public License getLicense() {
return getLicense("");
}
public void uninstallLicense() {
uninstallLicense("");
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy