List of usage examples for java.util Calendar roll
public void roll(int field, int amount)
From source file:org.apache.falcon.converter.OozieFeedWorkflowBuilderTest.java
@Test public void testRetentionCoords() throws FalconException, JAXBException, IOException { org.apache.falcon.entity.v0.feed.Cluster cluster = FeedHelper.getCluster(feed, srcCluster.getName()); final Calendar instance = Calendar.getInstance(); instance.roll(Calendar.YEAR, 1); cluster.getValidity().setEnd(instance.getTime()); OozieFeedWorkflowBuilder builder = new OozieFeedWorkflowBuilder(feed); List<COORDINATORAPP> coords = builder.getCoordinators(srcCluster, new Path("/projects/falcon/")); COORDINATORAPP coord = coords.get(0); Assert.assertEquals(coord.getAction().getWorkflow().getAppPath(), "${nameNode}/projects/falcon/RETENTION"); Assert.assertEquals(coord.getName(), "FALCON_FEED_RETENTION_" + feed.getName()); Assert.assertEquals(coord.getFrequency(), "${coord:hours(6)}"); HashMap<String, String> props = new HashMap<String, String>(); for (Property prop : coord.getAction().getWorkflow().getConfiguration().getProperty()) { props.put(prop.getName(), prop.getValue()); }//from w w w . jav a2s. c om String feedDataPath = props.get("feedDataPath"); String storageType = props.get("falconFeedStorageType"); // verify the param that feed evictor depends on Assert.assertEquals(storageType, Storage.TYPE.FILESYSTEM.name()); final Storage storage = FeedHelper.createStorage(cluster, feed); if (feedDataPath != null) { Assert.assertEquals(feedDataPath, storage.getUriTemplate().replaceAll(Storage.DOLLAR_EXPR_START_REGEX, Storage.QUESTION_EXPR_START_REGEX)); } if (storageType != null) { Assert.assertEquals(storageType, storage.getType().name()); } // verify the post processing params Assert.assertEquals(props.get("feedNames"), feed.getName()); Assert.assertEquals(props.get("feedInstancePaths"), "IGNORE"); assertWorkflowRetries(coord); }
From source file:org.apache.falcon.converter.OozieFeedWorkflowBuilderTest.java
@Test(dataProvider = "secureOptions") public void testRetentionCoordsForTable(String secureOption) throws Exception { StartupProperties.get().setProperty(SecurityUtil.AUTHENTICATION_TYPE, secureOption); org.apache.falcon.entity.v0.feed.Cluster cluster = FeedHelper.getCluster(tableFeed, trgCluster.getName()); final Calendar instance = Calendar.getInstance(); instance.roll(Calendar.YEAR, 1); cluster.getValidity().setEnd(instance.getTime()); OozieFeedWorkflowBuilder builder = new OozieFeedWorkflowBuilder(tableFeed); List<COORDINATORAPP> coords = builder.getCoordinators(trgCluster, new Path("/projects/falcon/")); COORDINATORAPP coord = coords.get(0); Assert.assertEquals(coord.getAction().getWorkflow().getAppPath(), "${nameNode}/projects/falcon/RETENTION"); Assert.assertEquals(coord.getName(), "FALCON_FEED_RETENTION_" + tableFeed.getName()); Assert.assertEquals(coord.getFrequency(), "${coord:hours(6)}"); HashMap<String, String> props = new HashMap<String, String>(); for (Property prop : coord.getAction().getWorkflow().getConfiguration().getProperty()) { props.put(prop.getName(), prop.getValue()); }// w w w . j ava 2s. c o m String feedDataPath = props.get("feedDataPath"); String storageType = props.get("falconFeedStorageType"); // verify the param that feed evictor depends on Assert.assertEquals(storageType, Storage.TYPE.TABLE.name()); final Storage storage = FeedHelper.createStorage(cluster, tableFeed); if (feedDataPath != null) { Assert.assertEquals(feedDataPath, storage.getUriTemplate().replaceAll(Storage.DOLLAR_EXPR_START_REGEX, Storage.QUESTION_EXPR_START_REGEX)); } if (storageType != null) { Assert.assertEquals(storageType, storage.getType().name()); } // verify the post processing params Assert.assertEquals(props.get("feedNames"), tableFeed.getName()); Assert.assertEquals(props.get("feedInstancePaths"), "IGNORE"); assertWorkflowRetries(coord); Assert.assertTrue(Storage.TYPE.TABLE == FeedHelper.getStorageType(tableFeed, trgCluster)); assertHCatCredentials(getWorkflowapp(coord), coord.getAction().getWorkflow().getAppPath().replace("${nameNode}", "")); }
From source file:com.marklogic.client.test.BitemporalTest.java
@Test public void c_testOther() throws Exception { String version1 = "<test>" + uniqueTerm + " version1" + "<system-start></system-start>" + "<system-end></system-end>" + "<valid-start>2014-08-19T00:00:00Z</valid-start>" + "<valid-end>2014-08-19T00:00:01Z</valid-end>" + "</test>"; String version2 = "<test>" + uniqueTerm + " version2" + "<system-start></system-start>" + "<system-end></system-end>" + "<valid-start>2014-08-19T00:00:02Z</valid-start>" + "<valid-end>2014-08-19T00:00:03Z</valid-end>" + "</test>"; String version3 = "<test>" + uniqueTerm + " version3" + "<system-start></system-start>" + "<system-end></system-end>" + "<valid-start>2014-08-19T00:00:03Z</valid-start>" + "<valid-end>2014-08-19T00:00:04Z</valid-end>" + "</test>"; String version4 = "<test>" + uniqueTerm + " version4" + "<system-start></system-start>" + "<system-end></system-end>" + "<valid-start>2014-08-19T00:00:05Z</valid-start>" + "<valid-end>2014-08-19T00:00:06Z</valid-end>" + "</test>"; // write four versions of the same document StringHandle handle1 = new StringHandle(version1).withFormat(Format.XML); docMgr.write(docId, null, handle1, null, null, temporalCollection); StringHandle handle2 = new StringHandle(version2).withFormat(Format.XML); docMgr.write(docId, null, handle2, null, null, temporalCollection); StringHandle handle3 = new StringHandle(version3).withFormat(Format.XML); TemporalDescriptor desc = docMgr.write(docId, null, handle3, null, null, temporalCollection); assertNotNull("Missing TemporalDescriptor from write", desc); assertEquals(docId, desc.getUri());/*from ww w.j a va2 s . c o m*/ String thirdWriteTimestamp = desc.getTemporalSystemTime(); Calendar thirdWriteTime = DatatypeConverter.parseDateTime(thirdWriteTimestamp); assertNotNull(thirdWriteTime); // add one millisecond since server precision is more precise, so Java truncates // fractions of a second here. Adding one millisecond ensures we're above the // system time for the last write for the document thirdWriteTime.roll(Calendar.MILLISECOND, true); StringHandle handle4 = new StringHandle(version4).withFormat(Format.XML); docMgr.write(docId, null, handle4, null, null, temporalCollection); // make sure non-temporal document read only returns the latest version DocumentPage readResults = docMgr.read(docId); assertEquals("Wrong number of results", 1, readResults.size()); DocumentRecord latestDoc = readResults.next(); assertEquals("Document uri wrong", docId, latestDoc.getUri()); // make sure a simple term query returns all versions of bulk and other docs StructuredQueryBuilder sqb = queryMgr.newStructuredQueryBuilder(); StructuredQueryDefinition termsQuery = sqb.or(sqb.term(uniqueTerm), sqb.term(uniqueBulkTerm)); long start = 1; DocumentPage termQueryResults = docMgr.search(termsQuery, start); assertEquals("Wrong number of results", 12, termQueryResults.size()); // temporal-collection is configured to automatically advance lsqt every 1 second // so we'll sleep for 2 seconds to make sure lsqt has advanced beyond the lsqt // when we inserted our documents Thread.sleep(2000); // query with lsqt of last inserted document // will match the first three versions -- not the last because it's equal to // not greater than the timestamp of this lsqt query StructuredQueryDefinition currentQuery = sqb.temporalLsqtQuery(temporalCollection, thirdWriteTime, 1); StructuredQueryDefinition currentDocQuery = sqb.and(termsQuery, currentQuery); DocumentPage currentDocQueryResults = docMgr.search(currentDocQuery, start); assertEquals("Wrong number of results", 11, currentDocQueryResults.size()); // query with blank lsqt indicating current time // will match all four versions currentQuery = sqb.temporalLsqtQuery(temporalCollection, "", 1); currentDocQuery = sqb.and(termsQuery, currentQuery); currentDocQueryResults = docMgr.search(currentDocQuery, start); assertEquals("Wrong number of results", 12, currentDocQueryResults.size()); StructuredQueryBuilder.Axis validAxis = sqb.axis("valid-axis"); // create a time axis to query the versions against Calendar start1 = DatatypeConverter.parseDateTime("2014-08-19T00:00:00Z"); Calendar end1 = DatatypeConverter.parseDateTime("2014-08-19T00:00:04Z"); StructuredQueryBuilder.Period period1 = sqb.period(start1, end1); // find all documents contained in the time range of our query axis StructuredQueryDefinition periodQuery1 = sqb.and(termsQuery, sqb.temporalPeriodRange(validAxis, TemporalOperator.ALN_CONTAINED_BY, period1)); DocumentPage periodQuery1Results = docMgr.search(periodQuery1, start); assertEquals("Wrong number of results", 3, periodQuery1Results.size()); // create a second time axis to query the versions against Calendar start2 = DatatypeConverter.parseDateTime("2014-08-19T00:00:04Z"); Calendar end2 = DatatypeConverter.parseDateTime("2014-08-19T00:00:07Z"); StructuredQueryBuilder.Period period2 = sqb.period(start2, end2); // find all documents contained in the time range of our second query axis StructuredQueryDefinition periodQuery2 = sqb.and(termsQuery, sqb.temporalPeriodRange(validAxis, TemporalOperator.ALN_CONTAINED_BY, period2)); DocumentPage periodQuery2Results = docMgr.search(periodQuery2, start); assertEquals("Wrong number of results", 3, periodQuery2Results.size()); for (DocumentRecord result : periodQuery2Results) { if (docId.equals(result.getUri())) { continue; } else if (result.getUri().startsWith("test_" + uniqueBulkTerm + "_4")) { continue; } fail("Unexpected uri for ALN_CONTAINED_BY test:" + result.getUri()); } // find all documents where valid time is after system time in the document StructuredQueryBuilder.Axis systemAxis = sqb.axis("system-axis"); StructuredQueryDefinition periodCompareQuery1 = sqb.and(termsQuery, sqb.temporalPeriodCompare(systemAxis, TemporalOperator.ALN_AFTER, validAxis)); DocumentPage periodCompareQuery1Results = docMgr.search(periodCompareQuery1, start); assertEquals("Wrong number of results", 12, periodCompareQuery1Results.size()); // find all documents where valid time is before system time in the document StructuredQueryDefinition periodCompareQuery2 = sqb.and(termsQuery, sqb.temporalPeriodCompare(systemAxis, TemporalOperator.ALN_BEFORE, validAxis)); DocumentPage periodCompareQuery2Results = docMgr.search(periodCompareQuery2, start); assertEquals("Wrong number of results", 0, periodCompareQuery2Results.size()); // check that we get a system time when we delete desc = docMgr.delete(docId, null, temporalCollection); assertNotNull("Missing TemporalDescriptor from delete", desc); assertEquals(docId, desc.getUri()); assertNotNull("Missing temporalSystemTime from delete", desc.getTemporalSystemTime()); }
From source file:org.apache.falcon.oozie.feed.OozieFeedWorkflowBuilderTest.java
@Test(dataProvider = "uMaskOptions") public void testRetentionCoords(String umask) throws Exception { FileSystem fs = srcMiniDFS.getFileSystem(); Configuration conf = fs.getConf(); conf.set("fs.permissions.umask-mode", umask); // ClusterHelper constructs new fs Conf. Add it to cluster properties so that it gets added to FS conf setUmaskInFsConf(srcCluster, umask); org.apache.falcon.entity.v0.feed.Cluster cluster = FeedHelper.getCluster(feed, srcCluster.getName()); final Calendar instance = Calendar.getInstance(); instance.roll(Calendar.YEAR, 1); cluster.getValidity().setEnd(instance.getTime()); OozieCoordinatorBuilder builder = OozieCoordinatorBuilder.get(feed, Tag.RETENTION); List<Properties> coords = builder.buildCoords(srcCluster, new Path("/projects/falcon/" + umask)); COORDINATORAPP coord = getCoordinator(srcMiniDFS, coords.get(0).getProperty(OozieEntityBuilder.ENTITY_PATH)); Assert.assertEquals(coord.getAction().getWorkflow().getAppPath(), "${nameNode}/projects/falcon/" + umask + "/RETENTION"); Assert.assertEquals(coord.getName(), "FALCON_FEED_RETENTION_" + feed.getName()); Assert.assertEquals(coord.getFrequency(), "${coord:hours(6)}"); HashMap<String, String> props = getCoordProperties(coord); HashMap<String, String> wfProps = getWorkflowProperties(fs, coord); String feedDataPath = wfProps.get("feedDataPath"); String storageType = wfProps.get("falconFeedStorageType"); // verify the param that feed evictor depends on Assert.assertEquals(storageType, Storage.TYPE.FILESYSTEM.name()); final Storage storage = FeedHelper.createStorage(cluster, feed); if (feedDataPath != null) { Assert.assertEquals(feedDataPath, storage.getUriTemplate().replaceAll(Storage.DOLLAR_EXPR_START_REGEX, Storage.QUESTION_EXPR_START_REGEX)); }//from www .ja v a 2 s . c o m if (storageType != null) { Assert.assertEquals(storageType, storage.getType().name()); } // verify the post processing params Assert.assertEquals(wfProps.get("feedNames"), feed.getName()); Assert.assertEquals(wfProps.get("feedInstancePaths"), "IGNORE"); assertWorkflowRetries(getWorkflowapp(srcMiniDFS.getFileSystem(), coord)); try { verifyClusterLocationsUMask(srcCluster, fs); verifyWorkflowUMask(fs, coord, umask); } finally { cleanupWorkflowState(fs, coord); FileSystem.closeAll(); } }
From source file:org.apache.falcon.oozie.feed.OozieFeedWorkflowBuilderTest.java
@Test(dataProvider = "secureOptions") public void testRetentionCoordsForTable(String secureOption) throws Exception { StartupProperties.get().setProperty(SecurityUtil.AUTHENTICATION_TYPE, secureOption); final String umask = "000"; FileSystem fs = trgMiniDFS.getFileSystem(); Configuration conf = fs.getConf(); conf.set("fs.permissions.umask-mode", umask); // ClusterHelper constructs new fs Conf. Add it to cluster properties so that it gets added to FS conf setUmaskInFsConf(trgCluster, umask); org.apache.falcon.entity.v0.feed.Cluster cluster = FeedHelper.getCluster(tableFeed, trgCluster.getName()); final Calendar instance = Calendar.getInstance(); instance.roll(Calendar.YEAR, 1); cluster.getValidity().setEnd(instance.getTime()); OozieCoordinatorBuilder builder = OozieCoordinatorBuilder.get(tableFeed, Tag.RETENTION); List<Properties> coords = builder.buildCoords(trgCluster, new Path("/projects/falcon/")); COORDINATORAPP coord = getCoordinator(trgMiniDFS, coords.get(0).getProperty(OozieEntityBuilder.ENTITY_PATH)); Assert.assertEquals(coord.getAction().getWorkflow().getAppPath(), "${nameNode}/projects/falcon/RETENTION"); Assert.assertEquals(coord.getName(), "FALCON_FEED_RETENTION_" + tableFeed.getName()); Assert.assertEquals(coord.getFrequency(), "${coord:hours(6)}"); HashMap<String, String> props = getCoordProperties(coord); HashMap<String, String> wfProps = getWorkflowProperties(fs, coord); String feedDataPath = wfProps.get("feedDataPath"); String storageType = wfProps.get("falconFeedStorageType"); // verify the param that feed evictor depends on Assert.assertEquals(storageType, Storage.TYPE.TABLE.name()); final Storage storage = FeedHelper.createStorage(cluster, tableFeed); if (feedDataPath != null) { Assert.assertEquals(feedDataPath, storage.getUriTemplate().replaceAll(Storage.DOLLAR_EXPR_START_REGEX, Storage.QUESTION_EXPR_START_REGEX)); }// w ww . ja v a 2 s. c o m if (storageType != null) { Assert.assertEquals(storageType, storage.getType().name()); } // verify the post processing params Assert.assertEquals(wfProps.get("feedNames"), tableFeed.getName()); Assert.assertEquals(wfProps.get("feedInstancePaths"), "IGNORE"); assertWorkflowRetries(coord); verifyBrokerProperties(srcCluster, wfProps); verifyEntityProperties(tableFeed, trgCluster, WorkflowExecutionContext.EntityOperations.DELETE, wfProps); Assert.assertTrue(Storage.TYPE.TABLE == FeedHelper.getStorageType(tableFeed, trgCluster)); assertHCatCredentials(getWorkflowapp(trgMiniDFS.getFileSystem(), coord), coord.getAction().getWorkflow().getAppPath().replace("${nameNode}", "")); try { verifyClusterLocationsUMask(trgCluster, fs); verifyWorkflowUMask(fs, coord, umask); } finally { cleanupWorkflowState(fs, coord); FileSystem.closeAll(); } }
From source file:com.rogchen.common.xml.UtilDateTime.java
/** * Returns a List of day name Strings - suitable for calendar headings. * * @param locale//from ww w. j a va 2 s .c o m * @return List of day name Strings */ public static List<String> getDayNames(Locale locale) { Calendar tempCal = Calendar.getInstance(locale); tempCal.set(Calendar.DAY_OF_WEEK, tempCal.getFirstDayOfWeek()); SimpleDateFormat dateFormat = new SimpleDateFormat("EEEE", locale); List<String> resultList = new ArrayList<String>(); for (int i = 0; i < 7; i++) { resultList.add(dateFormat.format(tempCal.getTime())); tempCal.roll(Calendar.DAY_OF_WEEK, 1); } return resultList; }
From source file:com.rogchen.common.xml.UtilDateTime.java
/** * Returns a List of month name Strings - suitable for calendar headings. * * @param locale/*from w w w . j a v a 2 s . c o m*/ * @return List of month name Strings */ public static List<String> getMonthNames(Locale locale) { Calendar tempCal = Calendar.getInstance(locale); tempCal.set(Calendar.MONTH, Calendar.JANUARY); SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM", locale); List<String> resultList = new ArrayList<String>(); for (int i = Calendar.JANUARY; i <= tempCal.getActualMaximum(Calendar.MONTH); i++) { resultList.add(dateFormat.format(tempCal.getTime())); tempCal.roll(Calendar.MONTH, 1); } return resultList; }
From source file:org.onebusaway.transit_data_federation.impl.realtime.gtfs_realtime.GtfsRealtimeTripLibrary.java
public void setCurrentTime(long currentTime, int originOffsetHours) { if (originOffsetHours != 0) { Calendar c = Calendar.getInstance(); c.setTime(new Date(currentTime)); c.roll(Calendar.HOUR, originOffsetHours); _currentTime = c.getTimeInMillis(); _log.info("currentTime set to " + new Date(_currentTime) + " from offset " + originOffsetHours); } else {// www . ja v a 2s . c om _currentTime = currentTime; } }
From source file:org.polymap.kaps.ui.filter.VertraegeStalaAgrarFilter.java
protected Query<VertragComposite> createFilterQuery(final IFilterEditorSite site, final KapsRepository repository) { Integer quartal = Integer.parseInt((String) site.getFieldValue("Quartal")); Integer jahr = Integer.parseInt((String) site.getFieldValue("Jahr")); Calendar lowerCal = new GregorianCalendar(); lowerCal.set(Calendar.YEAR, jahr); lowerCal.set(Calendar.DAY_OF_MONTH, 1); lowerCal.set(Calendar.HOUR_OF_DAY, 0); lowerCal.set(Calendar.MINUTE, 0); lowerCal.set(Calendar.SECOND, 0); lowerCal.set(Calendar.MILLISECOND, 0); Calendar upperCal = new GregorianCalendar(); upperCal.setTime(lowerCal.getTime()); switch (quartal) { case 1:// w w w . j a v a 2 s . co m lowerCal.set(Calendar.MONTH, Calendar.JANUARY); upperCal.set(Calendar.MONTH, Calendar.APRIL); break; case 2: lowerCal.set(Calendar.MONTH, Calendar.APRIL); upperCal.set(Calendar.MONTH, Calendar.JULY); break; case 3: lowerCal.set(Calendar.MONTH, Calendar.JULY); upperCal.set(Calendar.MONTH, Calendar.OCTOBER); break; case 4: lowerCal.set(Calendar.MONTH, Calendar.OCTOBER); upperCal.roll(Calendar.YEAR, true); upperCal.set(Calendar.MONTH, Calendar.JANUARY); break; default: throw new IllegalStateException("Quartal " + quartal + " unbekannt!"); } FlurstueckComposite flurstueckTemplate = QueryExpressions.templateFor(FlurstueckComposite.class); VertragComposite vertragTemplate = QueryExpressions.templateFor(VertragComposite.class); BooleanExpression dExpr = null; BooleanExpression vExpr = null; { Query<VertragComposite> vertraege = repository().findEntities(VertragComposite.class, QueryExpressions.and(QueryExpressions.ge(vertragTemplate.vertragsDatum(), lowerCal.getTime()), QueryExpressions.lt(vertragTemplate.vertragsDatum(), upperCal.getTime())), 0, -1); for (VertragComposite kv : vertraege) { BooleanExpression newExpr = QueryExpressions.eq(flurstueckTemplate.vertrag(), kv); if (vExpr == null) { vExpr = newExpr; } else { vExpr = QueryExpressions.or(vExpr, newExpr); } } } // falls keine Vertrge gefunden werden, wrden spter alle Flurstcke // selektiert -> StackOverFlow if (vExpr != null) { BooleanExpression nExpr = null; { Query<NutzungComposite> nutzungen = repository().findEntities(NutzungComposite.class, null, 0, -1); for (NutzungComposite nutzung : nutzungen) { if (nutzung.isAgrar().get() != null && nutzung.isAgrar().get() == Boolean.TRUE) { BooleanExpression newExpr = QueryExpressions.eq(flurstueckTemplate.nutzung(), nutzung); if (nExpr == null) { nExpr = newExpr; } else { nExpr = QueryExpressions.or(nExpr, newExpr); } } } } GemeindeComposite gemeinde = (GemeindeComposite) site.getFieldValue("gemeinde"); BooleanExpression gExpr = null; if (gemeinde != null) { GemarkungComposite gemarkungTemplate = QueryExpressions.templateFor(GemarkungComposite.class); Query<GemarkungComposite> gemarkungen = repository().findEntities(GemarkungComposite.class, QueryExpressions.eq(gemarkungTemplate.gemeinde(), gemeinde), 0, -1); for (GemarkungComposite gemarkung : gemarkungen) { BooleanExpression newExpr = QueryExpressions.eq(flurstueckTemplate.gemarkung(), gemarkung); if (gExpr == null) { gExpr = newExpr; } else { gExpr = QueryExpressions.or(gExpr, newExpr); } } } BooleanExpression expr = QueryExpressions.gt(flurstueckTemplate.verkaufteFlaeche(), 1000d); if (vExpr != null) { expr = QueryExpressions.and(expr, vExpr); } if (nExpr != null) { expr = QueryExpressions.and(expr, nExpr); } if (gExpr != null) { expr = QueryExpressions.and(expr, gExpr); } Query<FlurstueckComposite> allFlurstuecke = repository().findEntities(FlurstueckComposite.class, expr, 0, getMaxResults()); for (FlurstueckComposite flurstueck : allFlurstuecke) { BooleanExpression newExpr = QueryExpressions.eq(vertragTemplate.identity(), flurstueck.vertrag().get().identity().get()); if (dExpr == null) { dExpr = newExpr; } else { dExpr = QueryExpressions.or(dExpr, newExpr); } } // flurstcksfilter angegeben und keine flurstcke gefunden if (dExpr == null) { dExpr = QueryExpressions.eq(vertragTemplate.identity(), "nothing"); } } else { dExpr = QueryExpressions.eq(vertragTemplate.identity(), "nothing"); } BooleanExpression geeignetExpr = QueryExpressions.eq(vertragTemplate.fuerAuswertungGeeignet(), Boolean.TRUE); if (dExpr != null) { dExpr = QueryExpressions.and(dExpr, geeignetExpr); } else { dExpr = geeignetExpr; } return repository().findEntities(VertragComposite.class, dExpr, 0, getMaxResults()); }
From source file:org.polymap.kaps.ui.filter.VertraegeStalaBaulandFilter.java
protected Query<VertragComposite> createFilterQuery(final IFilterEditorSite site, final KapsRepository repository) { Integer quartal = Integer.parseInt((String) site.getFieldValue("Quartal")); Integer jahr = Integer.parseInt((String) site.getFieldValue("Jahr")); Calendar lowerCal = new GregorianCalendar(); lowerCal.set(Calendar.YEAR, jahr); lowerCal.set(Calendar.DAY_OF_MONTH, 1); lowerCal.set(Calendar.HOUR_OF_DAY, 0); lowerCal.set(Calendar.MINUTE, 0); lowerCal.set(Calendar.SECOND, 0); lowerCal.set(Calendar.MILLISECOND, 0); Calendar upperCal = new GregorianCalendar(); upperCal.setTime(lowerCal.getTime()); switch (quartal) { case 1:/*ww w. j ava 2 s. c om*/ lowerCal.set(Calendar.MONTH, Calendar.JANUARY); upperCal.set(Calendar.MONTH, Calendar.APRIL); break; case 2: lowerCal.set(Calendar.MONTH, Calendar.APRIL); upperCal.set(Calendar.MONTH, Calendar.JULY); break; case 3: lowerCal.set(Calendar.MONTH, Calendar.JULY); upperCal.set(Calendar.MONTH, Calendar.OCTOBER); break; case 4: lowerCal.set(Calendar.MONTH, Calendar.OCTOBER); upperCal.roll(Calendar.YEAR, true); upperCal.set(Calendar.MONTH, Calendar.JANUARY); break; default: throw new IllegalStateException("Quartal " + quartal + " unbekannt!"); } FlurstueckComposite flurstueckTemplate = QueryExpressions.templateFor(FlurstueckComposite.class); VertragComposite vertragTemplate = QueryExpressions.templateFor(VertragComposite.class); BooleanExpression dExpr = null; BooleanExpression vExpr = null; { Query<VertragComposite> vertraege = repository().findEntities(VertragComposite.class, QueryExpressions.and(QueryExpressions.ge(vertragTemplate.vertragsDatum(), lowerCal.getTime()), QueryExpressions.lt(vertragTemplate.vertragsDatum(), upperCal.getTime())), 0, -1); for (VertragComposite kv : vertraege) { BooleanExpression newExpr = QueryExpressions.eq(flurstueckTemplate.vertrag(), kv); if (vExpr == null) { vExpr = newExpr; } else { vExpr = QueryExpressions.or(vExpr, newExpr); } } } // falls keine Vertrge gefunden werden, wrden spter alle Flurstcke // selektiert -> StackOverFlow if (vExpr != null) { BooleanExpression nExpr = null; { Query<NutzungComposite> nutzungen = repository().findEntities(NutzungComposite.class, null, 0, -1); for (NutzungComposite nutzung : nutzungen) { if (nutzung.isAgrar().get() == null || nutzung.isAgrar().get() == Boolean.FALSE) { BooleanExpression newExpr = QueryExpressions.eq(flurstueckTemplate.nutzung(), nutzung); if (nExpr == null) { nExpr = newExpr; } else { nExpr = QueryExpressions.or(nExpr, newExpr); } } } } GemeindeComposite gemeinde = (GemeindeComposite) site.getFieldValue("gemeinde"); BooleanExpression gExpr = null; if (gemeinde != null) { GemarkungComposite gemarkungTemplate = QueryExpressions.templateFor(GemarkungComposite.class); Query<GemarkungComposite> gemarkungen = repository().findEntities(GemarkungComposite.class, QueryExpressions.eq(gemarkungTemplate.gemeinde(), gemeinde), 0, -1); for (GemarkungComposite gemarkung : gemarkungen) { BooleanExpression newExpr = QueryExpressions.eq(flurstueckTemplate.gemarkung(), gemarkung); if (gExpr == null) { gExpr = newExpr; } else { gExpr = QueryExpressions.or(gExpr, newExpr); } } } BooleanExpression expr = QueryExpressions.gt(flurstueckTemplate.verkaufteFlaeche(), 100d); if (vExpr != null) { expr = QueryExpressions.and(expr, vExpr); } if (nExpr != null) { expr = QueryExpressions.and(expr, nExpr); } if (gExpr != null) { expr = QueryExpressions.and(expr, gExpr); } Query<FlurstueckComposite> allFlurstuecke = repository().findEntities(FlurstueckComposite.class, expr, 0, getMaxResults()); for (FlurstueckComposite flurstueck : allFlurstuecke) { BooleanExpression newExpr = QueryExpressions.eq(vertragTemplate.identity(), flurstueck.vertrag().get().identity().get()); if (dExpr == null) { dExpr = newExpr; } else { dExpr = QueryExpressions.or(dExpr, newExpr); } } // flurstcksfilter angegeben und keine flurstcke gefunden if (dExpr == null) { dExpr = QueryExpressions.eq(vertragTemplate.identity(), "nothing"); } } else { dExpr = QueryExpressions.eq(vertragTemplate.identity(), "nothing"); } BooleanExpression geeignetExpr = QueryExpressions.eq(vertragTemplate.fuerAuswertungGeeignet(), Boolean.TRUE); if (dExpr != null) { dExpr = QueryExpressions.and(dExpr, geeignetExpr); } else { dExpr = geeignetExpr; } return repository().findEntities(VertragComposite.class, dExpr, 0, getMaxResults()); }