All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.computate.smartvillage.enus.page.HomePage Maven / Gradle / Ivy

Go to download

Red Hat Global Social Innovation Program is partnering with Boston University and Smarta Byar in order to collaborate on creating a global and open research platform allowing researchers to study what social sustainability means by using a digital twin of Veberöd, Sweden as the test village, supported by Smarta Byar. The goal of this collaboration is to build the open source technological infrastructure so that researchers can collaborate on this platform effectively to study mobility, public health, sustainability among other study areas to ultimately help define better the link between well being and eco-smart cities.

There is a newer version: 2.0.2
Show newest version
/*
 * Copyright (c) 2018-2022 Computate Limited Liability Company in Utah, USA,
 * and the Smarta Byar Smart Village FIWARE IHub. 
 *
 * This program and the accompanying materials are made available under the
 * terms of the GNU GENERAL PUBLIC LICENSE Version 3 which is available at
 * 
 * https://www.gnu.org/licenses/gpl-3.0.en.html
 * 
 * You may not propagate or modify a covered work except as expressly provided 
 * under this License. Any attempt otherwise to propagate or modify it is void, 
 * and will automatically terminate your rights under this License (including 
 * any patent licenses granted under the third paragraph of section 11).
 */
package org.computate.smartvillage.enus.page;


import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Optional;

import org.apache.commons.lang3.StringUtils;
import org.computate.search.response.solr.SolrResponse;
import org.computate.search.wrap.Wrap;
import org.computate.smartvillage.enus.config.ConfigKeys;
import org.computate.smartvillage.enus.model.page.SitePage;
import org.computate.smartvillage.enus.page.HomePageGen;
import org.computate.smartvillage.enus.page.PageLayout;
import org.computate.vertx.search.list.SearchList;

import io.vertx.core.Promise;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;

/**
 * Promise: true
 */
public class HomePage extends HomePageGen {


	/**
	 * {@inheritDoc}
	 * Ignore: true
	 **/
	protected void _searchListSitePage(Promise> promise) {
		SearchList l = new SearchList<>();
		l.q("*:*");
		l.sortDesc("courseNum_docvalues_int desc, lessonNum_docvalues_int");
		l.fq(String.format("created_docvalues_date:[* TO %s]", ZonedDateTime.now().toInstant().atOffset(ZoneOffset.UTC).format(DateTimeFormatter.ISO_DATE_TIME)));
		l.setC(SitePage.class);
		l.setStore(true);
		promise.complete(l);
	}

	protected void _pageResponse(Wrap w) {
		if(searchListSitePage != null)
			w.o(JsonObject.mapFrom(searchListSitePage.getResponse()).toString());
	}

	protected void _defaultZoneId(Wrap w) {
		w.o(Optional.ofNullable(siteRequest_.getRequestVars().get(VAR_defaultZoneId)).orElse(siteRequest_.getConfig().getString(ConfigKeys.SITE_ZONE)));
	}

	/**
	 * Ignore: true
	 **/
	protected void _defaultTimeZone(Wrap w) {
		w.o(ZoneId.of(defaultZoneId));
	}

	protected void _defaultLocaleId(Wrap w) {
		w.o(Optional.ofNullable(siteRequest_.getRequestHeaders().get("Accept-Language")).map(acceptLanguage -> StringUtils.substringBefore(acceptLanguage, ",")).orElse(siteRequest_.getConfig().getString(ConfigKeys.SITE_LOCALE)));
	}

	/**
	 * Ignore: true
	 **/
	protected void _defaultLocale(Wrap w) {
		w.o(Locale.forLanguageTag(defaultLocaleId));
	}

	protected void _defaultFieldListVars(List l) {
		Optional.ofNullable(searchListSitePage.getFields()).orElse(Arrays.asList()).forEach(varStored -> {
			String varStored2 = varStored;
			if(StringUtils.contains(varStored2, "}"))
				varStored2 = StringUtils.substringAfterLast(varStored2, "}");
			String[] parts = varStored2.split(",");
			for(String part : parts) {
				if(StringUtils.isNotBlank(part)) {
					String var = SitePage.searchVarSitePage(part);
					if(StringUtils.isNotBlank(var))
						l.add(var);
				}
			}
		});
	}

	protected void _defaultStatsVars(List l) {
		Optional.ofNullable(searchListSitePage.getStatsFields()).orElse(Arrays.asList()).forEach(varIndexed -> {
			String varIndexed2 = varIndexed;
			if(StringUtils.contains(varIndexed2, "}"))
				varIndexed2 = StringUtils.substringAfterLast(varIndexed2, "}");
			String[] parts = varIndexed2.split(",");
			for(String part : parts) {
				if(StringUtils.isNotBlank(part)) {
					String var = SitePage.searchVarSitePage(part);
					if(StringUtils.isNotBlank(var))
						l.add(var);
				}
			}
		});
	}

	protected void _defaultPivotVars(List l) {
		Optional.ofNullable(searchListSitePage.getFacetPivots()).orElse(Arrays.asList()).forEach(facetPivot -> {
			String facetPivot2 = facetPivot;
			if(StringUtils.contains(facetPivot2, "}"))
				facetPivot2 = StringUtils.substringAfterLast(facetPivot2, "}");
			String[] parts = facetPivot2.split(",");
			for(String part : parts) {
				if(StringUtils.isNotBlank(part)) {
					String var = SitePage.searchVarSitePage(part);
					if(StringUtils.isNotBlank(var))
						l.add(var);
				}
			}
		});
	}

	/**
	 * {@inheritDoc}
	 **/
	protected void _listSitePage(JsonArray l) {
		Optional.ofNullable(searchListSitePage).map(o -> o.getList()).orElse(Arrays.asList()).stream().map(o -> JsonObject.mapFrom(o)).forEach(o -> l.add(o));
	}

	protected void _stats(Wrap w) {
		w.o(searchListSitePage.getResponse().getStats());
	}

	protected void _facetCounts(Wrap w) {
		w.o(searchListSitePage.getResponse().getFacetCounts());
	}

	protected void _sitePageCount(Wrap w) {
		w.o(searchListSitePage == null ? 0 : searchListSitePage.size());
	}

	protected void _sitePages(Wrap> w) {
			w.o(searchListSitePage.getList());
	}

	@Override
	protected void _pageImageUri(Wrap c) {
			c.o("/png/iot-node-999.png");
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy