SharePoint List Service Recursive not working - sharepoint

I am using the following code to retrieve the documents in a list. Its working fine. However, it only returns documents and folders in root of the doc library. Is there any thing wrong I am doing here? I am looking for files in sub folders with recursive mode.
Service service = new Service();
service.setMaintainSession(true);
call = (Call) service.createCall();
call.setTargetEndpointAddress( new java.net.URL("<host>/_vti_bin/lists.asmx") );
call.setOperationName(new QName("http://schemas.microsoft.com/sharepoint/soap/","GetListItems"));
call.setProperty(Call.SOAPACTION_USE_PROPERTY, new Boolean("true"));
call.setProperty(Call.SOAPACTION_URI_PROPERTY,"http://schemas.microsoft.com/sharepoint/soap/GetListItems");
call.addParameter(new javax.xml.namespace.QName("http://schemas.microsoft.com/sharepoint/soap/", "listName"),
new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"),
java.lang.String.class,
javax.xml.rpc.ParameterMode.IN);
MessageElement me =
new MessageElement(new QName("QueryOptions"));
me.addChildElement(new MessageElement(new QName(
"IncludeMandatoryColumns"))).addTextNode("true");
me.addChildElement(new MessageElement(new QName(
"ViewAttributes"))).addAttribute(javax.xml.soap.SOAPFactory.newInstance().createName("Scope"), "Recursive");
MessageElement[] me1 = {me};
String strMyString = ""
+ "<Query>"
+ "<OrderBy><FieldRef Name=\"ows_Modified\" Ascending=\"TRUE\" /></OrderBy>"
+ "</Query>";
MessageElement[] meArray = { getMeFromString(strMyString) };// Array
call.addParameter("query",org.apache.axis.Constants.XSD_SCHEMA,
javax.xml.rpc.ParameterMode.IN);
call.addParameter("queryOptions",org.apache.axis.Constants.XSD_SCHEMA,
javax.xml.rpc.ParameterMode.IN);
call.setReturnType(org.apache.axis.Constants.XSD_SCHEMA);
Schema ret = (Schema)call.invoke(new Object[] {"listGUID",meArray, me1 });
public org.apache.axis.message.MessageElement getMeFromString(final String strMyString) {
DocumentBuilder docBuilder = null;
try {
docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
} catch (final ParserConfigurationException e) {
e.printStackTrace();
} catch (final FactoryConfigurationError e) {
e.printStackTrace();
}
final StringReader reader = new StringReader(strMyString);
final InputSource inputsource = new InputSource(reader);
Document doc = null;
try {
doc = docBuilder.parse(inputsource);
} catch (final SAXException e) {
e.printStackTrace();
} catch (final IOException e) {
e.printStackTrace();
}
final Element ele = doc.getDocumentElement();
final MessageElement msg = new MessageElement(ele);
return msg;
}

query.ViewAttributes = "Scope='RecursiveAll'"

Related

Nifi: how to remove session based on atribute value in nifi

I want to remove session in case i get certain data from file i have code like this,but i got errors "flowfile has already marked for removal", what should i change to get rid of extra errors?
In case of session rollback flowfile will dissapear in queues also?
2.should i use rollback instead of remove()?
NodeList childNodes = nodeGettingChanged.getChildNodes();
for (int i = 0; i != childNodes.getLength(); ++i) {
Node child = childNodes.item(i);
if (!(child instanceof Element))
continue;
if (child.getNodeName().equals("runAs")) {
if(child.getFirstChild().getTextContent()=="false"){
session.remove(flowFile1);
File deleteExtraFile =new File("C://Users//s.tkhilaishvili//Desktop//try2//nifi-1.3.0//1//conf.xml");
boolean delete=deleteExtraFile.delete();
}
else {
child.getFirstChild().setNodeValue("false");
}
}
}
Document finalXmlDocument = xmlDocument;
session.write(flowFile1, new StreamCallback() {
public void process(InputStream inputStream, OutputStream outputStream) throws IOException {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = null;
try {
transformer = transformerFactory.newTransformer();
} catch (TransformerConfigurationException e) {
e.printStackTrace();
}
DOMSource source = new DOMSource(finalXmlDocument);
ffStream.close();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
StreamResult result = new StreamResult(bos);
try {
transformer.transform(source, result);
} catch (TransformerException e) {
e.printStackTrace();
}
byte[] array = bos.toByteArray();
outputStream.write(array);
}
});
session.remove(flowFile);
session.transfer(flowFile1, REL_SUCCESS);
}
If you are executing session.remove(flowFile1) then later trying to transfer it to REL_SUCCESS, you will get that error. It looks like you already have an if-clause checking the firstChild for "false", perhaps you could put the transfer in an else-clause, such that it will only be transferred if it wasn't removed.

Nifi: can't recognize groovy xmlSlurper structure

[enter image description here][1]I have nifi 1.3.0. Is it possible that groovy version which is implemented in nifi can't recognize lambdas? Here is my code, how can I change it to make work inside nifi processor?
is it possible that processor doesn;t work properly because i don't use session.tranfer i mean don't produce any flowfile?
def static addDays(def date) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
c.setTime(sdf.parse(date));
c.add(Calendar.DATE, 1); // number of days to add
String m = sdf.format(c.getTime()); // dt is now the new date
return m;
}
def flowFile=session.get()
ArrayList<String> value = new ArrayList<>();
if(flowFile!=null){
value.add(flowFile.getAttribute('filename');
session.remove(flowFile);
}
File file = new File("C://Users//user//Desktop//try2//nifi-1.3.0//4//conf2.xml");
String content = "";
String material = "";
BufferedReader s;
BufferedWriter w;
RandomAccessFile ini = new RandomAccessFile(file, "rwd");
FileLock lock = ini.getChannel().lock();
DocumentBuilder dBuilder;
Document document, doc;
String date="",data="";
try {
String sCurrentLine;
s = new BufferedReader(Channels.newReader(ini.getChannel(), "UTF-8"));
while ((sCurrentLine = s.readLine()) != null) {
content += sCurrentLine;
}
ini.seek(0);
def xml = new XmlParser().parseText(content)
for(int i=0;i<value.size();i++) {
date = value.get(i).substring(0, 10);
xml.rs.borderCross.details.findAll({ p ->
p.runAs[0].text() == "false" && p.start[0].text() == date.toString()
}).each({ p ->
p.start[0].value = addDays( p.start[0].text())
p.runAs[0].value = "true"
})
}
def stringWriter = new StringWriter()
new XmlNodePrinter(new PrintWriter(stringWriter)).print(xml)
def newXml = stringWriter.toString()
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
InputStream stream1 = new ByteArrayInputStream(newXml.toString().getBytes("UTF-8"));
DocumentBuilderFactory dbFactory1 = DocumentBuilderFactory.newInstance();
dBuilder = dbFactory1.newDocumentBuilder();
document = dBuilder.parse(stream1);
DOMSource source=new DOMSource(document);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
StreamResult result1 = new StreamResult(bos);
try {
transformer.transform(source, result1);
} catch (TransformerException e) {
e.printStackTrace();
}
byte[] array = bos.toByteArray();
data = bos.toString();
if (!data.isEmpty()) {
ini.setLength(0);
w = new BufferedWriter(Channels.newWriter(ini.getChannel(), "UTF-8"));
w.write(data);
lock.release();
w.close();
}
else{
ini.setLength(0);
w = new BufferedWriter(Channels.newWriter(ini.getChannel(), "UTF-8"));
w.write(content);
lock.release();
w.close();
}
}catch (FileNotFoundException e) {
TimeUnit.SECONDS.sleep(50000);
} catch (IOException e) {
e.printStackTrace();
} catch (TransformerConfigurationException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (OverlappingFileLockException e) {
TimeUnit.SECONDS.sleep(50000);
lock.release(); ;
} catch (Exception e) {
e.printStackTrace();
} finally {
//lock.release();
ini.close();
}
Those aren't Java lambdas, they are Groovy closures. At first glance that looks correct, what error(s) are you getting? You may need to put the closures in parentheses before chaining them:
def xml = new XmlParser().parseText(content)
for(int i=0;i<value.size();i++) {
date = value.get(i).substring(0, 10);
xml.rs.borderCross.details.findAll({ p ->
p.runAs[0].text() == "false" && p.start[0].text() == date.toString()
}).each({ p ->
p.start[0].value = addDays( p.start[0].text())
p.runAs[0].value = "true"
})
}

Saving data read from sql database

I have four textboxes and a metrogrid, inside the textboxes data is read into them from sql database, but while saving the data in the textboxes one will save and others will vanish. Please i need help
this is the code for search button:
private void btnSearch_Click(object sender, EventArgs e)
{
try
{
using (SqlConnection connection = new SqlConnection(#"server = .\sql2012; database = dbAcceptance; integrated security = true; "))
{
SqlCommand command = new SqlCommand($"select * from acceptance WHERE regno = {txtregno.Text}", connection);
connection.Open();
SqlDataReader read = command.ExecuteReader();
if (read.Read())
{
txtfullname.Text = (read["fullname"].ToString());
txtdepartment.Text = (read["Department"].ToString());
txtfaculty.Text = (read["faculty"].ToString());
txtmodeofstudy.Text = (read["modeofstudy"].ToString());
txtprogramme.Text = (read["programmeofstudy"].ToString());
}
else
MetroFramework.MetroMessageBox.Show(this, "Reg No Not Found...Please Try Again", "Message");
read.Close();
}
}
catch (Exception ex)
{
//MetroFramework.MetroMessageBox.Show(this, ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
This is the code for add button:
private void btnAdd_Click(object sender, EventArgs e)
{
objState = EntityState.Added;
pContainer.Enabled = true;
registeredBindingSource.Add(new Registered());
registeredBindingSource.MoveLast();
txtregno.Focus();
}
This is the code for the save button:
private void btnSave_Click(object sender, EventArgs e)
{
try
{
registeredBindingSource.EndEdit();
Registered obj = registeredBindingSource.Current as Registered;
if (obj != null)
{
using (IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString))
{
if (db.State == ConnectionState.Closed)
db.Open();
if (objState == EntityState.Added)
{
DynamicParameters p = new DynamicParameters();
p.Add("#StudentID", dbType: DbType.Int32, direction: ParameterDirection.Output);
p.AddDynamicParams(new {
FullName = txtfullname.Text,
RegNo = txtregno.Text,
CourseTitle = obj.CourseTitle,
CourseStatus = obj.CourseStatus,
CourseUnit = obj.CourseUnit,
Department = txtdepartment.Text,
CurrentSemester = obj.CurrentSemester,
CurrentSession = obj.CurrentSession,
ModeOfStudy = txtmodeofstudy.Text,
Level = obj.Level,
ProgrammeOfStudy = txtprogramme.Text,
Faculty = txtfaculty.Text, finalSemester = obj.finalSemester
});
db.Execute("sp_StudentRegisteredCourse_insert", p, commandType: CommandType.StoredProcedure);
obj.StudentID = p.Get<int>("#StudentID");
}
else
{
db.Execute("sp_StudentRegisteredCourse_update", new { StudentID = obj.StudentID,FullName = txtfullname.Text,RegNo = txtregno.Text, CourseTitle = obj.CourseTitle,CourseStatus = obj.CourseStatus, CourseUnit = obj.CourseUnit, Department = txtdepartment.Text, CurrentSemester = obj.CurrentSemester,CurrentSession = obj.CurrentSession, ModeOfStudy = txtmodeofstudy.Text, Level = obj.Level, ProgrammeOfStudy = txtprogramme.Text,Faculty = txtfaculty.Text, finalSemester = obj.finalSemester },commandType:CommandType.StoredProcedure);
}
gridContainer.Refresh();
pContainer.Enabled = false;
objState = EntityState.unchanged;
}
}
}
catch (Exception ex)
{
MetroFramework.MetroMessageBox.Show(this, ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

Reading a file in Blackberry

I am trying to read content from file in blackberry and i read the file content to result object and when i am trying to print the result object it gives error and the file is in res folder,and this is code that i got problem
private String readTextFile(String fName) {
String result = null;
FileConnection fconn = null;
DataInputStream is = null;
try {
fconn = (FileConnection) Connector.open(fName, Connector.READ_WRITE);
is = fconn.openDataInputStream();
byte[] data = IOUtilities.streamToBytes(is);
result = new String(data);
System.out.println("result data is ...... "+result);
} catch (IOException e) {
System.out.println(e.getMessage());
} finally {
try {
if (null != is)
is.close();
if (null != fconn)
fconn.close();
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
return result;
}
what is fName here ?
The file name or the path could cause similar problem.

Not able to get DirContext ctx using Spring Ldap

Hi i am using Spring ldap , after execution below program It display I am here only and after that nothing is happening, program is in continue execution mode.
public class SimpleLDAPClient {
public static void main(String[] args) {
Hashtable env = new Hashtable();
System.out.println("I am here");
String principal = "uid="+"a502455"+", ou=People, o=ao, dc=com";
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "MYURL");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, principal);
env.put(Context.SECURITY_CREDENTIALS,"PASSWORD");
DirContext ctx = null;
NamingEnumeration results = null;
try {
ctx = new InitialDirContext(env);
System.out.println(" Context" + ctx);
SearchControls controls = new SearchControls();
controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
results = ctx.search("", "(objectclass=aoPerson)", controls);
while (results.hasMore()) {
SearchResult searchResult = (SearchResult) results.next();
Attributes attributes = searchResult.getAttributes();
Attribute attr = attributes.get("cn");
String cn = (String) attr.get();
System.out.println(" Person Common Name = " + cn);
}
} catch (NamingException e) {
throw new RuntimeException(e);
} finally {
if (results != null) {
try {
results.close();
} catch (Exception e) {
}
}
if (ctx != null) {
try {
ctx.close();
} catch (Exception e) {
}
}
}
}
}
Try fixing the below lines, i removed "ao" and it works fine.
results = ctx.search("", "(objectclass=Person)", controls);
You need to give search base as well
env.put(Context.PROVIDER_URL, "ldap://xx:389/DC=test,DC=enterprise,DC=xx,DC=com");
Refer this link as well http://www.adamretter.org.uk/blog/entries/LDAPTest.java

Resources