use of org.haiku.haikudepotserver.security.model.AuthorizationRulesSpreadsheetJobSpecification in project haikudepotserver by haiku.
the class AuthorizationJobApiImpl method queueAuthorizationRulesSpreadsheet.
@Override
public QueueAuthorizationRulesSpreadsheetResult queueAuthorizationRulesSpreadsheet(QueueAuthorizationRulesSpreadsheetRequest request) {
Preconditions.checkArgument(null != request, "a request objects is required");
final ObjectContext context = serverRuntime.newContext();
User user = obtainAuthenticatedUser(context);
if (!permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), null, Permission.AUTHORIZATION_CONFIGURE)) {
String msg = "attempt to queue authorization spreadsheet without sufficient authorization";
LOGGER.warn(msg);
throw new AccessDeniedException(msg);
}
QueueAuthorizationRulesSpreadsheetResult result = new QueueAuthorizationRulesSpreadsheetResult();
result.guid = jobService.submit(new AuthorizationRulesSpreadsheetJobSpecification(), JobSnapshot.COALESCE_STATUSES_QUEUED_STARTED);
return result;
}
use of org.haiku.haikudepotserver.security.model.AuthorizationRulesSpreadsheetJobSpecification in project haikudepotserver by haiku.
the class AuthorizationRulesSpreadsheetJobRunner method run.
@Override
public void run(JobService jobService, AuthorizationRulesSpreadsheetJobSpecification specification) throws IOException, JobRunnerException {
final ObjectContext context = serverRuntime.newContext();
DateTimeFormatter dateTimeFormatter = DateTimeHelper.createStandardDateTimeFormat();
// this will register the outbound data against the job.
JobDataWithByteSink jobDataWithByteSink = jobService.storeGeneratedData(specification.getGuid(), "download", MediaType.CSV_UTF_8.toString());
try (OutputStream outputStream = jobDataWithByteSink.getByteSink().openBufferedStream();
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
CSVWriter writer = new CSVWriter(outputStreamWriter, ',')) {
writer.writeNext(new String[] { "create-timestamp", "user-nickname", "user-active", "permission-code", "permission-name", "pkg-name" });
ObjectSelect<PermissionUserPkg> objectSelect = ObjectSelect.query(PermissionUserPkg.class).orderBy(PermissionUserPkg.USER.dot(User.NICKNAME).asc(), PermissionUserPkg.PERMISSION.dot(Permission.CODE).asc());
try (ResultBatchIterator<PermissionUserPkg> batchIterator = objectSelect.batchIterator(context, 50)) {
batchIterator.forEach((pups) -> pups.forEach((pup) -> writer.writeNext(new String[] { dateTimeFormatter.format(Instant.ofEpochMilli(pup.getCreateTimestamp().getTime())), pup.getUser().getNickname(), Boolean.toString(pup.getUser().getActive()), pup.getPermission().getCode(), pup.getPermission().getName(), null != pup.getPkg() ? pup.getPkg().getName() : "" })));
}
writer.flush();
outputStreamWriter.flush();
}
}
Aggregations