Our goal is to fetch some of the content from Liferay Portal via SOAP services using Java. We are successfully loading articles right now with JournalArticleServiceSoap. The problem is that the method requires both group id and entry id, and what we want is to fetch all of the articles from a particular group. Hence, we are trying to get the ids first, using AssetEntryServiceSoap but it fails.
AssetEntryServiceSoapServiceLocator aesssLocator = new AssetEntryServiceSoapServiceLocator();
com.liferay.client.soap.portlet.asset.service.http.AssetEntryServiceSoap assetEntryServiceSoap = null;
URL url = null;
try {
url = new URL(
"http://127.0.0.1:8080/tunnel-web/secure/axis/Portlet_Asset_AssetEntryService");
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
assetEntryServiceSoap = aesssLocator
.getPortlet_Asset_AssetEntryService(url);
} catch (ServiceException e) {
e.printStackTrace();
}
if (assetEntryServiceSoap == null) {
return;
}
Portlet_Asset_AssetEntryServiceSoapBindingStub assetEntryServiceSoapBindingStub = (Portlet_Asset_AssetEntryServiceSoapBindingStub) assetEntryServiceSoap;
assetEntryServiceSoapBindingStub.setUsername("bruno#7cogs.com");
assetEntryServiceSoapBindingStub.setPassword("bruno");
AssetEntrySoap[] entries;
AssetEntryQuery query = new AssetEntryQuery();
try {
int count = assetEntryServiceSoap.getEntriesCount(query);
System.out.println("Entries count: " + Integer.toString(count));
entries = assetEntryServiceSoap.getEntries(query);
if (entries != null) {
System.out.println(Integer.toString(entries.length));
}
for (AssetEntrySoap aes : assetEntryServiceSoap.getEntries(query)) {
System.out.println(aes.getEntryId());
}
} catch (RemoteException e1) {
e1.printStackTrace();
}
Although getEntriesCount() returns a positive value like 83, getEnries() always returns an empty array. I'm very new to Liferay portal, but it looks really weird to me.
By the way, we are obviously not looking for performance here, the key is just to fetch some specific content from the portal remotely. If you know any working solution your help would be much appreciated.
Normally a AssetEntryQuery would have a little more information in it for example:
AssetEntryQuery assetEntryQuery = new AssetEntryQuery();
assetEntryQuery.setClassNameIds(new long[] { ClassNameLocalServiceUtil.getClassNameId("com.liferay.portlet.journal.model.JournalArticle") });
assetEntryQuery.setGroupIds(new long[] { groupId });
So this would return all AssetEntries for the groupId you specify, that are also JournalArticles.
Try this and see, although as you say, the Count method returns a positive number so it might not make a difference, but give it a go! :)
Related
I'm trying Jgit and I want to retrieve all tags of a cloned repository and I want to sort them by Date. That's why I'm trying the following:
String path = "path/to/my/git/repo/.git";
Repository repository = builder.setGitDir(new File(path)).readEnvironment().findGitDir().build();
try (RevWalk walk = new RevWalk(repository)) {
List<Ref> taglist = new Git(repository).tagList().call();
Collections.sort(taglist, new Comparator<Ref>() {
public int compare(Ref o1, Ref o2) {
Date d1 = null;
Date d2 = null;
try {
d1 = walk.parseTag(o1.getObjectId()).getTaggerIdent().getWhen();
d2 = walk.parseTag(o2.getObjectId()).getTaggerIdent().getWhen();
} catch (IOException e) {
e.printStackTrace();
}
return d1.compareTo(d2);
}
});
}catch (GitAPIException e){
e.printStackTrace();
}
}
The problem is that some of Ref returned by this.taglist = new Git(repository).tagList().call() are not Tag: in fact an exception is raised by parseTag() and its message is:
org.eclipse.jgit.errors.IncorrectObjectTypeException: Object 3ea2b388b5ef02622312fe08e6935a5f9c655e00 is not a tag.
Can someone explain me why this happen and how can i solve the problem? Thank you all.
As I said in the comment, i solved changing the walk.parseTag(o1.getObjectId()).getTaggerIdent().getWhen(); into walk.parseCommit(o1.getObjectId()).getAuthorIdent().getWhen(); and same for o2.
Hope this will help others.
JGit's Git.tagList() returns a org.eclipse.jgit.api.ListTagCommand.
ListTagCommand.call() returns type List<Ref> as documented.
The Ref interface is implemented by ObjectIdRef, ObjectIdRef.PeeledNonTag, ObjectIdRef.PeeledTag, ObjectIdRef.Unpeeled, and SymbolicRef.
You should check the type of the returned value before attempting to do anything with it, or use a try/catch as you have done.
I am facing an issue when i try to query the queue using createquery api to fetch the queue element.
I am getting an error at the while statement stating the error below as
errorjava.lang.illegalstateexception :unread block data
i dont know why i am getting this error. I can able to use the fetchcount() api to get the count of workitem in the queue but the hasnext() api is not working nor next().
Is there any reason why this statement is not getting executed. is this related to any java issue. Can any one help
The code is
VWSession session = new VWSession();
session.setBootstrapCEURI(Ceuri);
session.logon(cename, fnPassword, connectionPoint);
VWQueue queue = session.getQueue(queue));
int queryFlag = VWQueue.QUERY_NO_OPTIONS;
int fetchType = VWFetchType.FETCH_TYPE_STEP_ELEMENT;
VWQueueQuery queueQuery = queue.createQuery(null,null, null,queryFlag, null, null, fetchType);
while (queueQuery.hasNext()) {
queueElement = (VWStepElement) queueQuery.next();
}
In you main (calling) method, do this :
VWSession vwsession = new VWSession();
vwsession.setBootstrapCEURI("http://servername:9080/wsi/FNCEWS40MTOM/");
vwsession.logon("userid", "password", "ConnPTName");
IteratePEWorkItems queueTest = new IteratePEWorkItems();
queueTest.testQueueElements(vwsession);
Later on create below metioned helper method:
public void testQueueElements(VWSession vwsession) {
System.out.println("Inside getListOfWorkitems: : ");
VWRoster roster = vwsession.getRoster("DefaultRoster");
int fetchType = VWFetchType.FETCH_TYPE_STEP_ELEMENT;
int queryFlags = VWQueue.QUERY_READ_UNWRITABLE;
try {
dispatchWorkItems(roster, fetchType, queryFlags, vwsession);
} catch (Exception exception) {
log.error(exception.getMessage());
}
}
public void dispatchWorkItems(VWRoster roster, int fetchType, int queryFlags, VWSession vwsession) {
String filter = "SLA_Date>=:A";
// get value and replace with 1234567890 as shown in process administrator
Object[] subVars = { 1234567890 };
VWRosterQuery rosterQuery = roster.createQuery(null, null, null,
VWRoster.QUERY_MIN_VALUES_INCLUSIVE | VWRoster.QUERY_MAX_VALUES_INCLUSIVE, filter, subVars,
VWFetchType.FETCH_TYPE_WORKOBJECT);
int i = 0;
// Iterate work items here...
while (rosterQuery.hasNext() == true) {
VWWorkObject workObject = (VWWorkObject) rosterQuery.next();
try {
i++;
System.out.println(" Subject: " + workObject.getFieldValue("F_Subject") + " Count: " + i);
} catch (Exception exception) {
exception.printStackTrace();
log.error(exception);
}
}
}
Try it and share the output.
I want to load some data using protocoll-buffers (JSON was way too slow on Android) but somehow my repeated field called company contains 6 copies of every element - although I am not storing any duplicates.
How do I know that it shouldn't contain duplicates?
I did set a counter for every object I am saving - and it was the expected length.
This is my schema:
syntax = "proto3";
[...]
message CompanyProtoRepository {
// THIS FIELD CONTAINS DUPLICATES!
repeated CompanyProto company = 1;
}
How I store my data:
public void writeToFile(String fileName) {
CompanyProtos.CompanyProtoRepository repo = loadRepository();
try {
OutputStream outputStream = mContext.openFileOutput(fileName, Context.MODE_PRIVATE);
repo.writeTo(outputStream);
} catch (Exception e) {
e.printStackTrace();
}
}
private CompanyProtos.CompanyProtoRepository loadRepository() {
CompanyLoaderService jsonLoader = new JsonCompanyLoaderService(mContext.getResources());
CompanyProtos.CompanyProtoRepositoryOrBuilder repo = CompanyProtos.CompanyProtoRepository.newBuilder();
int counter = 0; // Will be 175 which is correct (every company 1 time)
// Will contain every id only time -> correct!
HashMap<Integer, Integer> map = new HashMap<>();
for (Company company : jsonLoader.getCompanies()) {
counter++;
if (!map.containsKey(company.getName()))
map.put(company.getId(), 1);
else
map.put(company.getId(), map.get(company.getId()) + 1);
CompanyProtos.CompanyProto proto = toProto(company);
if (!repo.getCompanyList().contains(proto))
((CompanyProtos.CompanyProtoRepository.Builder) repo).addCompany(proto);
}
return ((CompanyProtos.CompanyProtoRepository.Builder) repo).build();
}
And this is how I load my data:
private List<Company> loadCompanies() {
CompanyProtos.CompanyProtoRepository repo = null;
try {
InputStream inputStream = mContext.getResources().openRawResource(R.raw.company_buffers);
repo = CompanyProtos.CompanyProtoRepository.parseFrom(inputStream);
ArrayList<Company> list = new ArrayList<>();
for (CompanyProtos.CompanyProto companyProto: repo.getCompanyList()) {
list.add(fromProto(companyProto));
}
// This list contains every company 6 times!
return list;
} catch (Exception ex) { }
}
Of course I expected to have each company only 1 time since I verfied that I store each company only time inside my CompanyProtoRepository instead of 6 times.
Oh my f**** godness.
I just spent hours and hours by trying to fix that bug.
Turns out I am reading from an old corrupt data-set - and not the file I am actually writing to.
I am fetching a course object by its course run id. Below is my code that works perfectly ok.
public static CourseVO getBlackboardCourseObjectByCourseRunID(String RunID){
CourseVO[] courseVOList = null;
try {
courseVOList = BlackboardCoursesDAO.getAllBlackBoardCourse();
} catch (RemoteException e) {
// TODO Auto-generated catch block
throw new RuntimeException("Not able to fetch blackboard courses");
}
CourseVO courseVO = new CourseVO();
int length=courseVOList.length;
System.out.println("length : "+length);
int i=0;
courseVO = courseVOList[i];
while(!courseVO.getId().equals(RunID) && i<length){
courseVO = courseVOList[i];
//System.out.println("in while loop ");
i++;
}
return courseVO;
}
But it troubles when I try to fetch this object in a loop.
If anyone can provide some better code, it will be great help.
Thanks.
After line 8, you can try to change lines with this>
Stream<CourseVO> courseList = Arrays.stream(courseVOList);
CourseVO foundCourse = courseList.filter(s -> s.getId().equals(RunID) )
.findFirst().get();
I have a program that connects to Db, using prepareCall. there is a function that browse some element from Db. this is part of this function:
Resource f = new Resource();
if (rs.next()) {
f.setAreaSrl(rs.getInt(1));
f.setAreaId(rs.getInt(2));
f.setAreaName(rs.getString(3));
f.setCenterX(rs.getFloat(4));
f.setCenterY(rs.getFloat(5));
f.setCenterZ(rs.getFloat(6));
}
return f;
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "problem in accessing DB");
e.printStackTrace();
return null;
}
and I have the folloing code in java:
Resource mzone = new Resource();
mzone.getOneEntityBase("areasrl=i");
that will give me a row of table. how can i access to them, element by element?
I want to do some calculation by this numbers, so i need to have them separately.
I have found some way to do it, but it doesn't work.
Resource mzone = new ResourceAreaZone();
mzone.getOneEntityBase("areasrl=1");
String name = mzone.getAreaName();
centerX = (int) mzone.getCenterX();