Through SDK Purge version is not working

Hello ,
I have written code for Purge version in SDK in that I want to purge previous version not latest one but it is not working.

Add Comment
2 Answer(s)

Please provide details so we can give assistance, such as code snippets, error messages, etc.

Agile Angel Answered on May 17, 2019.

Hello,
Kindly find the code for it .
import java.util.*;

import com.agile.api.*;

public class DeletFile {
public static IAgileSession session=null;
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
try {
session=Connect.connect();
//Scanner sc=new Scanner(System.in);
//System.out.println(“Enter file folder number”);
//String AsmName=sc.next();
IDesign file= (IDesign)session.getObject(IDesign.OBJECT_TYPE, “Test_SDK”);
System.out.println(“FileFolder” + file.getName() );

checkOut(file);
removeFile(file);
removeStructure(file);
checkIn(file);
//purgeVersion(file);

} catch (APIException e) {
// TODO Auto-generated catch block

e.printStackTrace();
}
finally {
session.close();
System.out.println(“Session Disconnected”);
}

}
public static void checkOut(IDesign ff) throws Exception{
ff.checkOutEx();
}
public static void removeFile(IDesign ff)throws Exception {
ITable file=ff.getTable(FileFolderConstants.TABLE_FILES);

file.clear();
System.out.println(“FIle table clear”);
}
public static void removeStructure(IDesign ff) throws APIException {
ITable structure=ff.getTable(FileFolderConstants.TABLE_STRUCTURE);
structure.clear();
System.out.println(“File Structure clear”);
}
public static void checkIn(IDesign ff) throws Exception{
ff.checkIn();
}

@SuppressWarnings(“unchecked”)
public static <T> void purgeVersion(IDesign ff) throws Exception{

System.out.println(“Current version is” +ff.getCurrentVersion());

Object[] obj=ff.getVersions();
Integer[] objint=new Integer[obj.length];
List<Object> obj3=new ArrayList(Arrays.asList(obj));
Collections.sort((List<T>) obj3);
System.out.println(obj3);

for(Integer i=1;i<objint.length;i++) {

//objint[i]=(Integer)obj[i];
//System.out.println(Arrays.toString(objint));
//System.out.println(objint);
// Integer[] obj1 = (Integer[]) obj[i];
//Object[] obj2 =obj1;
// System.out.println(“Value of version purge is ” +obj2);
//ff.purgeVersions((obj1));
if(i<objint.length) {
System.out.println(i);
//Object[] file1= (Object[]) ff.getCurrentVersion();

//Integer[] file1int=new Integer[file1.length];
//System.out.println(“Version of file is” +file1int);
//ff.purgeVersions(ff.getObjectVersion());

}
else {
System.out.println(“One version remain”);
}
}
//System.out.println(obj);
System.out.println(“Version purged”);
//ff.purgeVersions(objint);

}

public static void delete(IFileFolder filefolder) throws APIException {
filefolder.delete();
}

}

on May 17, 2019.

Hello,
I want to purge previous version. If i used purgeversions() method as it purge latest value.

on May 17, 2019.

Hello,
 Itried multiple ways but facing different error out of this below is one

Exception in thread “main” java.lang.ClassCastException: java.lang.Integer cannot be cast to [Ljava.lang.Object;
at Excersise.DeletFile.purgeVersion(DeletFile.java:72)
at Excersise.DeletFile.main(DeletFile.java:23)

on May 17, 2019.
Add Comment

Hello Dhananjay

  Looking thro’ Javadoc, it is expecting Integer Array (even if it is only one) instead of Integer. Make it to an array and give it a try

<<
Parameters:

  versions  numbers to be purged. only Integer[] is expected.

Agile Angel Answered on May 17, 2019.

Hello,
Thanks for reply already i try but throwing error .and purgeversion() method need input in object array. So first i get all versions in object array then type casted to integer array and then try to pass through this method still it throwing error.
below is code can you pl help.
package Excersise;

import java.util.*;

import com.agile.api.*;

public class DeletFile {
public static IAgileSession session=null;
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
try {
session=Connect.connect();
//Scanner sc=new Scanner(System.in);
//System.out.println(“Enter file folder number”);
//String AsmName=sc.next();
IDesign file= (IDesign)session.getObject(IDesign.OBJECT_TYPE, “Test_SDK”);
System.out.println(“FileFolder” + file.getName() );

checkOut(file);
removeFile(file);
removeStructure(file);
checkIn(file);
//purgeVersion(file);

} catch (APIException e) {
// TODO Auto-generated catch block

e.printStackTrace();
}
finally {
session.close();
System.out.println(“Session Disconnected”);
}

}
public static void checkOut(IDesign ff) throws Exception{
ff.checkOutEx();
}
public static void removeFile(IDesign ff)throws Exception {
ITable file=ff.getTable(FileFolderConstants.TABLE_FILES);

file.clear();
System.out.println(“FIle table clear”);
}
public static void removeStructure(IDesign ff) throws APIException {
ITable structure=ff.getTable(FileFolderConstants.TABLE_STRUCTURE);
structure.clear();
System.out.println(“File Structure clear”);
}
public static void checkIn(IDesign ff) throws Exception{
ff.checkIn();
}

@SuppressWarnings(“unchecked”)
public static <T> void purgeVersion(IDesign ff) throws Exception{

System.out.println(“Current version is” +ff.getCurrentVersion());

Object[] obj=ff.getVersions();
Integer[] objint=new Integer[obj.length];
List<Object> obj3=new ArrayList(Arrays.asList(obj));
Collections.sort((List<T>) obj3);
System.out.println(obj3);

for(Integer i=1;i<objint.length;i++) {

//objint[i]=(Integer)obj[i];
//System.out.println(Arrays.toString(objint));
//System.out.println(objint);
// Integer[] obj1 = (Integer[]) obj[i];
//Object[] obj2 =obj1;
// System.out.println(“Value of version purge is ” +obj2);
//ff.purgeVersions((obj1));
if(i<objint.length) {
System.out.println(i);
//Object[] file1= (Object[]) ff.getCurrentVersion();

//Integer[] file1int=new Integer[file1.length];
//System.out.println(“Version of file is” +file1int);
//ff.purgeVersions(ff.getObjectVersion());

}
else {
System.out.println(“One version remain”);
}
}
//System.out.println(obj);
System.out.println(“Version purged”);
//ff.purgeVersions(objint);

}

public static void delete(IFileFolder filefolder) throws APIException {
filefolder.delete();
}

}

on May 18, 2019.

Ah ok. Since there were several comments, I wasn’t sure which was getting executed. I just went by the exception

Will give a try and let you know.BTW, which version of Agile are you on?

on May 18, 2019.

Hello,
 We are on 9.3.6 
public static void purgeVersion(IDesign ff) throws Exception{

Object[] obj=ff.getVersions();
Integer[] objint=new Integer[obj.length];
for(Integer i=1;i<objint.length;i++) {
ff.setCurrentVersion(i);

Object[] ob1 =(Object[]) ff.getCurrentVersion();
System.out.println(“Current version is” +ob1);
Object [] ob2=(Object[]) ob1;

ff.purgeVersions(ob2);
}

this is seperated method snippet . hope it will clear to. In this i get current version then stored in object array but when i pass this in purgeversion method it throw error.

on May 20, 2019.

Ok. We are also on same version RUP7. Will give it a try shortly

on May 20, 2019.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.