/*
 * oxTrust is available under the MIT License (2008). See http://opensource.org/licenses/MIT for full text.
 *
 * Copyright (c) 2014, Gluu
 */

package org.gluu.oxtrust.service.custom;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;

import org.gluu.model.custom.script.model.CustomScript;
import org.gluu.oxtrust.service.OrganizationService;
import org.gluu.persist.PersistenceEntryManager;
import org.gluu.service.custom.script.AbstractCustomScriptService;

/**
 * Operations with custom scripts
 *
 * @author Yuriy Movchan Date: 12/03/2014
 */
@ApplicationScoped
public class CustomScriptService extends AbstractCustomScriptService {

	@Inject
	private OrganizationService organizationService;

	@Inject
	private PersistenceEntryManager persistenceEntryManager;

	private static final long serialVersionUID = -5283102477313448031L;

	public String baseDn() {
		String orgDn = organizationService.getDnForOrganization();
		return String.format("ou=scripts,%s", orgDn);
	}

	public CustomScript getScriptByInum(String inum) {
		CustomScript result = null;
		try {
			result = persistenceEntryManager.find(CustomScript.class, buildDn(inum));
		} catch (Exception ex) {
		}
		return result;
	}

}

@@ -262,16 +262,70 @@
 nject;%0A%0A
+import org.gluu.model.custom.script.CustomScriptType;%0A
 import o
@@ -372,16 +372,16 @@
 Script;%0A
-
 import o
@@ -425,16 +425,63 @@
 ervice;%0A
+import org.gluu.oxtrust.util.OxTrustConstants;%0A
 import o
@@ -521,16 +521,54 @@
 anager;%0A
+import org.gluu.search.filter.Filter;%0A
 import o
@@ -625,16 +625,75 @@
 Service;
+%0Aimport org.gluu.util.StringHelper;%0A%0Aimport java.util.List;
 %0A%0A/**%0A *
@@ -1416,14 +1416,1765 @@
 result;%0A
-
 %09%7D%0A
+%09public List%3CCustomScript%3E findCustomAuthScripts(String pattern, int sizeLimit) %7B%0A%09%09String%5B%5D targetArray = new String%5B%5D %7B pattern %7D;%0A%09%09Filter descriptionFilter = Filter.createSubstringFilter(OxTrustConstants.DESCRIPTION, null, targetArray, null);%0A%09%09Filter scriptTypeFilter = Filter.createEqualityFilter(%22oxScriptType%22, CustomScriptType.PERSON_AUTHENTICATION);%0A%09%09Filter displayNameFilter = Filter.createSubstringFilter(OxTrustConstants.displayName, null, targetArray, null);%0A%09%09Filter searchFilter = Filter.createORFilter(descriptionFilter, displayNameFilter);%0A%09%09return  persistenceEntryManager.findEntries(getDnForCustomScript(null), CustomScript.class,%0A%09%09%09%09Filter.createANDFilter(searchFilter, scriptTypeFilter), sizeLimit);%0A%09%7D%0A%0A%09public List%3CCustomScript%3E findOtherCustomScripts(String pattern, int sizeLimit) %7B%0A%09%09String%5B%5D targetArray = new String%5B%5D %7B pattern %7D;%0A%09%09Filter descriptionFilter = Filter.createSubstringFilter(OxTrustConstants.DESCRIPTION, null, targetArray, null);%0A%09%09Filter scriptTypeFilter = Filter.createNOTFilter(Filter.createEqualityFilter(%22oxScriptType%22, CustomScriptType.PERSON_AUTHENTICATION));%0A%09%09Filter displayNameFilter = Filter.createSubstringFilter(OxTrustConstants.displayName, null, targetArray, null);%0A%09%09Filter searchFilter = Filter.createORFilter(descriptionFilter, displayNameFilter);%0A%09%09return  persistenceEntryManager.findEntries(getDnForCustomScript(null), CustomScript.class,%0A%09%09%09%09Filter.createANDFilter(searchFilter, scriptTypeFilter), sizeLimit);%0A%09%7D%0A%0A%0A%09public String getDnForCustomScript(String inum) %7B%0A%09%09String orgDn = organizationService.getDnForOrganization();%0A%09%09if (StringHelper.isEmpty(inum)) %7B%0A%09%09%09return String.format(%22ou=scripts,%25s%22, orgDn);%0A%09%09%7D%0A%09%09return String.format(%22inum=%25s,ou=scripts,%25s%22, inum, orgDn);%0A%09%7D%0A%0A
 %0A%7D%0A

Add extra methods for api.