Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

to create the a new base Java backend class to render the page for taxonomies related to RNA seqence runs. #52

Open
computate opened this issue Oct 19, 2021 · 0 comments

Comments

@computate
Copy link
Member

Mission to create the a new base Java backend class to render the page for taxonomies related to RNA seqence runs.

Mission

Your mission, should you choose to accept it, is to create the a new base Java backend class to render the page for taxonomies related to RNA seqence runs. .

The day of the operation is October 26th, 2021

You will have 4 hours to complete your mission.

An open science project to uncover the planetary virome, freely and openly

You will be joining a team of the boldest

of all Red Hatters for this mission, who will be at your service developing the code and automating the deployment to OpenShift.

  • Should you, or any of your force be taken or compromised that day, you must report back as many changes as you have made, and any knowledge of your actions, by pull request or comments on the issue on the board.

How to get started:

Follow the instructions here to setup the project: https://github.com/team19hackathon2021/serratus-api/

The details of your mission:

  • The Java package name will be: io.serratus.api.enus.model.taxonomy
  • The Java class name will be: TaxonomyGenPage
  • The path to the Java class will be: /usr/local/src/serratus-api/src/main/java/io/serratus/api/enus/model/taxonomy/TaxonomyGenPage.java
  • The Java class will extend: TaxonomyGenPageGen<BaseModelPage>
package io.serratus.api.enus.model.taxonomy;

import java.lang.String;
import io.serratus.api.enus.base.BaseModelPage;
import io.serratus.api.enus.request.SiteRequestEnUS;
import io.serratus.api.enus.user.SiteUser;
import java.io.IOException;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.core.http.HttpServerResponse;
import io.serratus.api.enus.search.SearchList;
import io.serratus.api.enus.wrap.Wrap;
import io.serratus.api.enus.page.PageLayout;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.LocalDate;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.api.service.ServiceRequest;
import io.vertx.core.json.JsonArray;
import java.net.URLDecoder;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.Map;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
import org.apache.solr.common.util.SimpleOrderedMap;
import java.util.stream.Collectors;
import java.util.Arrays;
import org.apache.solr.client.solrj.response.QueryResponse;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.math.MathContext;
import org.apache.commons.collections.CollectionUtils;
import java.util.Objects;
import org.apache.solr.client.solrj.SolrQuery.SortClause;
import io.vertx.core.Promise;
import io.serratus.api.enus.config.ConfigKeys;

/**
 **/

public class TaxonomyGenPage extends TaxonomyGenPageGen<BaseModelPage> {
}

Create the init method for the searchListTaxonomy_ field inside the TaxonomyGenPage class

Create an initialization method that starts with an underscore ()searchListTaxonomy to define the searchListTaxonomy_ field

Here is a suggestion on what the code might look like:

	protected void _searchListTaxonomy_(Wrap<SearchList<Taxonomy>> w) {
	}

Create the init method for the listTaxonomy field inside the TaxonomyGenPage class

Create an initialization method that starts with an underscore (_)listTaxonomy to define the listTaxonomy field

Here is a suggestion on what the code might look like:

protected void _listTaxonomy(JsonArray l) {
		Optional.ofNullable(searchListTaxonomy_).map(o -> o.getList()).orElse(Arrays.asList()).stream().map(o -> JsonObject.mapFrom(o)).forEach(o -> l.add(o));
	}

Create the init method for the taxonomyCount field inside the TaxonomyGenPage class

Create an initialization method that starts with an underscore (_)taxonomyCount to define the taxonomyCount field

Here is a suggestion on what the code might look like:

	protected void _taxonomyCount(Wrap<Integer> w) {
		w.o(searchListTaxonomy_ == null ? 0 : searchListTaxonomy_.size());
	}

Create the init method for the taxonomy_ field inside the TaxonomyGenPage class

Create an initialization method that starts with an underscore ()taxonomy to define the taxonomy_ field

Here is a suggestion on what the code might look like:

	protected void _taxonomy_(Wrap<Taxonomy> w) {
		if(taxonomyCount == 1)
			w.o(searchListTaxonomy_.get(0));
	}

Create the init method for the pk field inside the TaxonomyGenPage class

Create an initialization method that starts with an underscore (_)pk to define the pk field

Here is a suggestion on what the code might look like:

	protected void _pk(Wrap<Long> w) {
		if(taxonomyCount == 1)
			w.o(taxonomy_.getPk());
	}

Create the _promiseBefore method inside the TaxonomyGenPage class

	protected void _promiseBefore(Promise<Void> promise) {
		promise.complete();
	}

Create the _classSimpleName method inside the TaxonomyGenPage class

	protected void _classSimpleName(Wrap<String> w) {
		w.o("Taxonomy");
	}

Create the _pageTitle method inside the TaxonomyGenPage class

	protected void _pageTitle(Wrap<String> c) {
		if(taxonomy_ != null && taxonomy_.getObjectTitle() != null)
			c.o(taxonomy_.getObjectTitle());
		else if(taxonomy_ != null)
			c.o("taxonomies");
		else if(searchListTaxonomy_ == null || taxonomyCount == 0)
			c.o("no taxonomy found");
		else
			c.o("taxonomies");
	}

Create the _pageUri method inside the TaxonomyGenPage class

	protected void _pageUri(Wrap<String> c) {
		c.o("/api/taxonomy");
	}

Create the _roles method inside the TaxonomyGenPage class

	protected void _roles(List<String> l) {
		if(siteRequest_ != null) {
			l.addAll(Stream.concat(siteRequest_.getUserResourceRoles().stream(), siteRequest_.getUserRealmRoles().stream()).distinct().collect(Collectors.toList()));
		}
	}

Create the _rolesRequired method inside the TaxonomyGenPage class

	protected void _rolesRequired(List<String> l) {
		l.addAll(Optional.ofNullable(siteRequest_.getConfig().getJsonArray(ConfigKeys.AUTH_ROLES_REQUIRED + "_Taxonomy")).orElse(new JsonArray()).stream().map(o -> o.toString()).collect(Collectors.toList()));
	}

Create the _pagination method inside the TaxonomyGenPage class

	protected void _pagination(JsonObject pagination) {
		JsonArray pages = new JsonArray();
		Long start = searchListTaxonomy_.getStart().longValue();
		Long rows = searchListTaxonomy_.getRows().longValue();
		Long foundNum = searchListTaxonomy_.getQueryResponse().getResults().getNumFound();
		Long startNum = start + 1L;
		Long endNum = start + rows;
		Long floorMod = Math.floorMod(foundNum, rows);
		Long last = Math.floorDiv(foundNum, rows) - (floorMod.equals(0L) ? 1L : 0L) * rows;
		endNum = endNum < foundNum ? endNum : foundNum;
		startNum = foundNum == 0L ? 0L : startNum;
		Long paginationStart = start - 10L * rows;
		if(paginationStart < 0L)
			paginationStart = 0L;
		Long paginationEnd = start + 10L * rows;
		if(paginationEnd > foundNum)
			paginationEnd = foundNum;

		pagination.put("1L", 1L);
		pagination.put("0L", 0L);
		pagination.put("start", start);
		pagination.put("rows", rows);
		pagination.put("rowsPrevious", rows / 2);
		pagination.put("rowsNext", rows * 2);
		pagination.put("startNum", startNum);
		pagination.put("endNum", endNum);
		pagination.put("foundNum", foundNum);
		pagination.put("pageStart", new JsonObject().put("start", 0L).put("pageNumber", 1L));
		if(start > 0L)
			pagination.put("pagePrevious", new JsonObject().put("start", start - rows).put("pageNumber", start - rows + 1L));
		if(start + rows < foundNum)
			pagination.put("pageNext", new JsonObject().put("start", start + rows).put("pageNumber", start + rows + 1L));
		pagination.put("pageEnd", new JsonObject().put("start", last).put("pageNumber", last + 1L));
		pagination.put("pages", pages);
		for(Long i = paginationStart; i < paginationEnd; i += rows) {
			Long pageNumber = Math.floorDiv(i, rows) + 1L;
			JsonObject page = new JsonObject();
			page.put("pageNumber", pageNumber);
			page.put("currentPage", start.equals(i));
			page.put("start", i);
			pages.add(page);
		}
	}

Create the _query method inside the TaxonomyGenPage class

	protected void _query(JsonObject query) {
		ServiceRequest serviceRequest = siteRequest_.getServiceRequest();
		JsonObject params = serviceRequest.getParams();

		JsonObject queryParams = Optional.ofNullable(serviceRequest).map(ServiceRequest::getParams).map(or -> or.getJsonObject("query")).orElse(new JsonObject());
		Long num = searchListTaxonomy_.getQueryResponse().getResults().getNumFound();
		String q = "*:*";
		String q1 = "objectText";
		String q2 = "";
		for(String paramName : queryParams.fieldNames()) {
			String entityVar = null;
			String valueIndexed = null;
			Object paramObjectValues = queryParams.getValue(paramName);
			JsonArray paramObjects = paramObjectValues instanceof JsonArray ? (JsonArray)paramObjectValues : new JsonArray().add(paramObjectValues);

			try {
				for(Object paramObject : paramObjects) {
					switch(paramName) {
					case "q":
						q = (String)paramObject;
						entityVar = StringUtils.trim(StringUtils.substringBefore((String)paramObject, ":"));
						valueIndexed = URLDecoder.decode(StringUtils.trim(StringUtils.substringAfter((String)paramObject, ":")), "UTF-8");
						q1 = entityVar.equals("*") ? q1 : entityVar;
						q2 = valueIndexed;
						q = q1 + ":" + q2;
					}
				}
			} catch(Exception e) {
				ExceptionUtils.rethrow(e);
			}
		}
		query.put("q", q);

		Integer rows1 = Optional.ofNullable(searchListTaxonomy_).map(l -> l.getRows()).orElse(10);
		Integer start1 = Optional.ofNullable(searchListTaxonomy_).map(l -> l.getStart()).orElse(1);
		Integer start2 = start1 - rows1;
		Integer start3 = start1 + rows1;
		Integer rows2 = rows1 / 2;
		Integer rows3 = rows1 * 2;
		start2 = start2 < 0 ? 0 : start2;
		JsonArray fqs = new JsonArray();
		for(String fq : Optional.ofNullable(searchListTaxonomy_).map(l -> l.getFilterQueries()).orElse(new String[0])) {
			if(!StringUtils.contains(fq, "(")) {
				String fq1 = StringUtils.substringBefore(fq, "_");
				String fq2 = StringUtils.substringAfter(fq, ":");
				if(!StringUtils.startsWithAny(fq, "classCanonicalNames_", "archived_", "deleted_", "sessionId", "userKeys"))
					fqs.add(new JsonObject().put("var", fq1).put("val", fq2));
				}
			}
		query.put("fq", fqs);

		JsonArray sorts = new JsonArray();
		for(SortClause sort : Optional.ofNullable(searchListTaxonomy_).map(l -> l.getSorts()).orElse(Arrays.asList())) {
			sorts.add(new JsonObject().put("var", StringUtils.substringBefore(sort.getItem(), "_")).put("order", sort.getOrder().name()));
		}
		query.put("sort", sorts);
	}

Create the _promiseAfter method inside the TaxonomyGenPage class

	protected void _promiseAfter(Promise<Void> promise) {
		promise.complete();
	}

Create the _pageImageUri method inside the TaxonomyGenPage class

	protected void _pageImageUri(Wrap<String> c) {
			c.o("/png/api/taxonomy-999.png");
	}

Create the _contextIconGroup method inside the TaxonomyGenPage class

	protected void _contextIconGroup(Wrap<String> c) {
			c.o("regular");
	}

Create the _contextIconName method inside the TaxonomyGenPage class

	protected void _contextIconName(Wrap<String> c) {
			c.o("project-diagram");
	}

This message will not self-destruct.

This message will not self destruct, because this project is open source.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant