ReportUpdatedMetadata implements Service { public Element exec(Element params, ServiceContext context) throws Exception { String beginDate = Util.getParam(params, "dateFrom"); String endDate = Util.getParam(params, "dateTo"); beginDate = beginDate + "T00:00:00"; endDate = endDate + "T23:59:59"; ISODate beginDateIso = new ISODate(beginDate); ISODate endDateIso = new ISODate(endDate); Set<Integer> groupList = ReportUtils.groupsForFilter(context, params); final List<? extends AbstractMetadata> records = context.getBean(IMetadataUtils.class).getMetadataReports(). getUpdatedMetadata(beginDateIso, endDateIso, groupList); Element response = new Element(Jeeves.Elem.RESPONSE); for (AbstractMetadata metadata : records) { User userOwner = context.getBean(UserRepository.class).findOne(metadata.getSourceInfo().getOwner()); final Integer mdGroupOwner = metadata.getSourceInfo().getGroupOwner(); String groupOwnerName = ""; String groupOwnerMail = ""; if (mdGroupOwner != null) { Group groupOwner = context.getBean(GroupRepository.class).findOne(mdGroupOwner); groupOwnerName = (groupOwner.getLabelTranslations().get(context.getLanguage()) != null ? groupOwner.getLabelTranslations().get(context.getLanguage()) : groupOwner.getName()); groupOwnerMail = (groupOwner.getEmail() != null ? groupOwner.getEmail() : ""); } String userOwnerUsername = userOwner.getUsername(); String userOwnerName = (userOwner.getName() != null ? userOwner.getName() : ""); String userOwnerSurname = (userOwner.getSurname() != null ? userOwner.getSurname() : ""); String userOwnerMail = (userOwner.getEmail() != null ? userOwner.getEmail() : ""); String mdTitle = ReportUtils.retrieveMetadataTitle(context, metadata.getId()); Element metadataEl = new Element("record"); metadataEl.addContent(new Element("uuid").setText(metadata.getUuid())) .addContent(new Element("recordName").setText("" + mdTitle)) .addContent(new Element("changedate").setText("" + metadata.getDataInfo().getChangeDate())) .addContent(new Element("username").setText(userOwnerUsername)) .addContent(new Element("surname").setText(userOwnerSurname)) .addContent(new Element("name").setText(userOwnerName)) .addContent(new Element("email").setText(userOwnerMail)) .addContent(new Element("groupName").setText(groupOwnerName)) .addContent(new Element("groupOwnerMail").setText(groupOwnerMail)); response.addContent(metadataEl); } return response; }  void init(Path appPath, ServiceConfig params); Element exec(Element params, ServiceContext context);  }
@Test public void testExec() throws Exception { final URL resource = AbstractCoreIntegrationTest.class.getResource("kernel/valid-metadata.iso19139.xml"); String uuid = UUID.randomUUID().toString(); ServiceContext importContext = createServiceContext(); loginAsAdmin(importContext); importMetadataXML(importContext, uuid, resource.openStream(), MetadataType.METADATA, ReservedGroup.all.getId(), uuid); uuid = UUID.randomUUID().toString(); final int mdId1 = importMetadataXML(importContext, uuid, resource.openStream(), MetadataType.METADATA, ReservedGroup.all.getId(), uuid); metadataRepository.update(mdId1, new Updater<Metadata>() { @Override public void apply(@Nonnull Metadata entity) { entity.getSourceInfo().setGroupOwner(null); } }); ServiceContext context = createServiceContext(); context.setUserSession(new UserSession()); final String now = getTomorrow(); final String lastMonth = getLastMonth(); assertRecords(0, createParams(read("dateFrom", now), read("dateTo", now)), context); assertRecords(2, createParams(read("dateFrom", lastMonth), read("dateTo", now)), context); assertRecords(0, createParams(read("dateFrom", lastMonth), read("dateTo", now), read("groups", "2"), read("groups", "42")), context); assertRecords(1, createParams(read("dateFrom", lastMonth), read("dateTo", now), read("groups", ReservedGroup.all.getId()), read("groups", "42")), context); loginAsAdmin(context); assertRecords(0, createParams(read("dateFrom", now), read("dateTo", now)), context); assertRecords(2, createParams(read("dateFrom", lastMonth), read("dateTo", now)), context); assertRecords(0, createParams(read("dateFrom", lastMonth), read("dateTo", now), read("groups", "2"), read("groups", "42")), context); assertRecords(1, createParams(read("dateFrom", lastMonth), read("dateTo", now), read("groups", ReservedGroup.all.getId()), read("groups", "42")), context); }