This question is answered.


Permlink Replies: 21 - Pages: 2 [ Previous | 1 2 ] - Last Post: 22-Apr-2017 17:55 Last Post By: jGromit Threads: [ Previous | Next ]
RobM

Posts: 3,345
Registered: 4-Aug-2006
Re: Deleting output under program control
Posted: 22-Apr-2017 16:08   in response to: jGromit in response to: jGromit
 
  Click to reply to this thread Reply
jGromit wrote:
No clue. I'll tinker.

Edit: No, I'm just getting increasingly bizarre errors. Perhaps David will check in and shed some light on this one.

For the moment, it's back to my brute force method, which does work.

Try
AlbumSynchronizer AlSy = new AlbumSynchronizer(engine);
			AlSy.delete(obj);

It works for PDF but still gets an error about registering variables on template pages. I will have a another look.
RobM

Posts: 3,345
Registered: 4-Aug-2006
Re: Deleting output under program control
Posted: 22-Apr-2017 16:20   in response to: RobM in response to: RobM
Correct
  Click to reply to this thread Reply
This works for both PDF and template pages
private void exUnsupp(AlbumObject ao, String path) {
	for(AlbumObject obj : ao.getChildren()) {
		cat = ao.getCategory();
		if(obj.isIncluded() && obj.isFolder()) exUnsupp(obj, path + "/" + obj.getVars().get("fileName"));
		else if(obj.isIncluded() && cat != Category.image && cat != Category.video) {
			obj.setIncluded(false);
			AlbumSynchronizer AlSy = new AlbumSynchronizer(engine);
			AlSy.delete(obj);
		}
		ao.setChildren(ao.getChildren());
	}
}
jGromit

Posts: 8,616
Registered: 31-Jan-2006
Re: Deleting output under program control
Posted: 22-Apr-2017 16:37   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
At first, that excluded absolutely everything. Took me a minute to spot why:
cat = ao.getCategory();
Um no, you want:
cat = obj.getCategory();
It's also no longer necessary to include the path information - the jAlbum method keeps track of that on its own. So, we end up with:
private void exUnsupp(AlbumObject ao) {
	for(AlbumObject obj : ao.getChildren()) {
		cat = obj.getCategory();
		if(obj.isIncluded() && obj.isFolder()) exUnsupp(obj);
		else if(obj.isIncluded() && cat != Category.image && cat != Category.video) {
			obj.setIncluded(false);
			AlbumSynchronizer AlSy = new AlbumSynchronizer(engine);
			AlSy.delete(obj);
		}
		ao.setChildren(ao.getChildren());
	}
}
I'll play with it some more, just to make sure it's not a phantom solution. ;)
davidekholm

Posts: 3,845
Registered: 18-Oct-2002
Re: Deleting output under program control
Posted: 22-Apr-2017 17:12   in response to: jGromit in response to: jGromit
Helpful
  Click to reply to this thread Reply
Just two small comments on your code:
  • Move the new AlbumSynchronizer call outside the iterator for performance (i.e before it)
  • Move the ao.setChildren(ao.getChildren()); call outside the iterator too (i.e. after it) for performance reasons, otherwise you will write to disk for each album object instead of doing one write per folder.
jGromit

Posts: 8,616
Registered: 31-Jan-2006
Re: Deleting output under program control
Posted: 22-Apr-2017 17:22   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
So, now you show up, eh, after RobM and I have struggled through to a solution!

Edit: Yes, it appears to be happy with this:
private void exUnsupp(AlbumObject ao) {
	AlbumSynchronizer AlSy = new AlbumSynchronizer(engine);
	for(AlbumObject obj : ao.getChildren()) {
		cat = obj.getCategory();
		if(obj.isIncluded() && obj.isFolder()) exUnsupp(obj);
		else if(obj.isIncluded() && cat != Category.image && cat != Category.video) {
			obj.setIncluded(false);
			AlSy.delete(obj);
		}
	}
	ao.setChildren(ao.getChildren());
}
RobM

Posts: 3,345
Registered: 4-Aug-2006
Re: Deleting output under program control
Posted: 22-Apr-2017 17:53   in response to: jGromit in response to: jGromit
 
  Click to reply to this thread Reply
Sorry about the ao.getCategory, just too used to using ao.

At least we have learnt something, that is having to make a new instance of the AlbumSynchronizer, but for us hacks having that in the API would make it that much easier to use.
jGromit

Posts: 8,616
Registered: 31-Jan-2006
Re: Deleting output under program control
Posted: 22-Apr-2017 17:55   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
Most API's are like a dictionary that shows you how to spell each word, and provides an exhaustive guide to its pronunciation, but doesn't actually tell you what the word means. ;)
Legend
Forum admins
Helpful Answer
Correct Answer

Point your RSS reader here for a feed of the latest messages in all forums