com.alogic.xscript.ldap.LDAPDel Maven / Gradle / Ivy
package com.alogic.xscript.ldap;
import com.alogic.xscript.ExecuteWatcher;
import com.alogic.xscript.Logiclet;
import com.alogic.xscript.LogicletContext;
import com.alogic.xscript.doc.XsObject;
import com.anysoft.util.*;
import org.apache.commons.lang3.StringUtils;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
/**
* LDAP删除条目
*/
public class LDAPDel extends LDAPConnection.Operation{
/**
* 条目的dn
*/
protected String $dn;
/**
* 结果id
*/
protected String id;
public LDAPDel(String tag, Logiclet p) {
super(tag, p);
}
@Override
public void configure(Properties p){
super.configure(p);
$dn = PropertiesConstants.getRaw(p,"dn",$dn);
id = PropertiesConstants.getString(p,"id","",true);
}
@Override
protected void onExecute(DirContext dirContext, XsObject root, XsObject current, LogicletContext ctx, ExecuteWatcher watcher) {
String dn = PropertiesConstants.transform(ctx,$dn,"");
if (StringUtils.isEmpty(dn)){
logger.error("The dn is null,operation is ignored.");
return ;
}
try {
dirContext.destroySubcontext(dn);
if (StringUtils.isNotEmpty(id)){
ctx.SetValue(id,"true");
}
}catch (NamingException ex){
logger.error("Can not create dir context:" + ex.toString());
if (StringUtils.isNotEmpty(id)){
ctx.SetValue(id,ex.getClass().getName());
ctx.SetValue(id + ".reason",ex.toString(true));
}
}
}
}