Quark Engine and JT400 - Part 3

In this post we will continue with our web exposed controllers showing you a simple skeleton to work with OUTQ and SPOOLS. We will show you how easy it is to manage or read spool files and outq.

As OUTQ and SPOOL files are separate objects on IBM i, we will do the same thing for our controllers by creating simple skeletons, each for one object type.

First, OutqController for handling OUTQ's

@ExtJSDirect(paths = { "/ws", "/api" })
@ExtJSAction(namespace = "io.greenscreens", action = "OUTQ")
public class OutqController {

	private static final Logger LOG = LoggerFactory.getLogger(OutqController.class);

	@Inject 
	AS400 as400;
	
	@PostConstruct
	public void init() {
		if (!as400.isUsePasswordCache()) {
			throw new RuntimeException("User not verified!");
		}
	}
	
	@ExtJSMethod("spools")
	public ExtJSResponseList<SpoolData> spools(final String outq) {		

		return new ExtJSResponseList<>(true, null);
	}

	@ExtJSMethod("list")
	public ExtJSResponseList<String> list() {		

		return new ExtJSResponseList<>(true, null);
	}

	@ExtJSMethod("clear")
	public ExtJSResponse clear(final String outq, final boolean allUsers) {

		return new ExtJSResponse(true, null);
	}

}

And, SpoolController for handling Spool Files

@ExtJSDirect(paths = { "/ws", "/api" })
@ExtJSAction(namespace = "io.greenscreens", action = "SPOOL")
public class SpoolController {

	enum STATE {HOLD, RELEASE} 
	
	@Inject 
	AS400 as400;
	
	@PostConstruct
	public void init() {
		if (!as400.isUsePasswordCache()) {
			throw new RuntimeException("User not verified!");
		}
	}
	
	@ExtJSMethod("load")
	public ExtJSResponse load(final SpoolData data) {		

		return new ExtJSResponse(true, null);
	}

	@ExtJSMethod("remove")
	public ExtJSResponse remove(final SpoolData data) {		

		return new ExtJSResponse(true, null);
	}

	@ExtJSMethod("move")
	public ExtJSResponse move(final SpoolData data, final String outq) {		

		return new ExtJSResponse(true, null);
	}

	@ExtJSMethod("state")
	public ExtJSResponse state(final SpoolData data, final STATE state) {

		return new ExtJSResponse(true, null);
	}
}

As one can see, it's quite straightforward.

In SpoolController we used SpoolData class definition to simplify and reduce method parameter pollution. Spool files can be uniquely found by several attributes such as spoolName, spoolNumber, spoolSequence, outq name etc. We decided to use data structure instead of adding all attributes individually.

Instead making calls as show in the first line, we will use later format.

io.greenscreens.SPOOL.remove('PRTQ', 'INVOICE', 1092929, 22);

let cfg = {outq:'PRTQ', name:'INVOICE', number:1092929, seq:22};
io.greenscreens.SPOOL.remove(cfg);

Our SpoolData structure used to filter or select spool  will look like this.

public class SpoolData {

	private String outq;
	private String sysName;
	private String spoolName;
	private int number;
	private String jobName;
	private String jobUser;
	private String jobNumber;

}

What remains is to add some logic. Here is a sample for deleting spool file.  

@ExtJSMethod("remove")
public ExtJSResponse remove(final SpoolData data) {		

	final ExtJSResponse.Builder builder = ExtJSResponse.Builder.create();
					
	try {
		final SpooledFile file = get(data);
		file.delete();
		builder.setStatus(true);
	} catch (Exception e) {
		builder.setMessage(e.getMessage());
		LOG.error(e.getMessage());
		LOG.debug(e.getMessage(), e);
	}
		
	return builder.build();
}

Full working source is updated on our GitHub repository here, under package demo3.