示例#1
0
func UUIDRender(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)

	// call mongo and lookup the redirection to use...
	session, err := services.GetMongoCon()
	if err != nil {
		panic(err)
	}
	defer session.Close()

	// Optional. Switch the session to a monotonic behavior.
	session.SetMode(mgo.Monotonic, true)
	c := session.DB("test").C("schemaorg")
	c2 := session.DB("test").C("csvwmeta")

	// Get the schema.org data
	URI := fmt.Sprintf("http://opencoredata.org/id/dataset/%s", vars["UUID"])
	result := SchemaOrgMetadata{}
	err = c.Find(bson.M{"url": URI}).One(&result)
	if err != nil {
		log.Printf("URL lookup error: %v", err)
	}

	// context setting hack
	// result.Context = ` "opencore": "http://opencoredata.org/voc/1/", "glview": "http://geolink.org/view/1/", "schema": "http://schema.org/"`
	result.Context = "http://schema.org"

	jsonldtext, _ := json.MarshalIndent(result, "", " ") // results as embeddale JSON-LD

	// Get the CSVW  data
	result2 := CSVWMeta{}
	err = c2.Find(bson.M{"url": URI}).One(&result2)
	if err != nil {
		log.Printf("URL lookup error: %v", err)
	}

	// result.Context = ` "opencore": "http://opencoredata.org/voc/1/", "glview": "http://geolink.org/view/1/", "schema": "http://schema.org/"`
	// needs to be:     "@context": ["http://www.w3.org/ns/csvw", {"@language": "en"}],
	result2.Context = "http://www.w3.org/ns/csvw"

	csvwtext, _ := json.MarshalIndent(result2, "", " ") // results as embeddale JSON-LD

	ht, err := template.New("some template").ParseFiles("templates/jrso_dataset_new.html") //open and parse a template text file
	if err != nil {
		log.Printf("template parse failed: %s", err)
	}

	// need a simple function call to extract the "janus" keyword from the keyword string and toLower it and
	// pass it in this struct to use in the data types web component
	measureString := getJanusKeyword(result.Keywords)
	dataForTemplate := TemplateForDoc{Schema: result, CSVW: result2, Schemastring: template.JS(string(jsonldtext)), Csvwstring: template.JS(string(csvwtext)), MeasureType: measureString, UUID: vars["UUID"]}

	err = ht.ExecuteTemplate(w, "T", dataForTemplate) //substitute fields in the template 't', with values from 'user' and write it out to 'w' which implements io.Writer
	if err != nil {
		log.Printf("htemplate execution failed: %s", err)
	}

	// go get the CSVW metadata and inject the whole package and the rendered table

}
示例#2
0
//todo this NOT what I want..   this is not Expeditions, this is features.....
func AllExpeditions(w http.ResponseWriter, r *http.Request) {
	// call mongo and lookup the redirection to use...
	session, err := services.GetMongoCon()
	if err != nil {
		panic(err)
	}
	defer session.Close()

	// Optional. Switch the session to a monotonic behavior.
	session.SetMode(mgo.Monotonic, true)
	c := session.DB("expedire").C("expeditions")

	var results []CruiseGL
	err = c.Find(bson.M{}).Sort("-expedition").All(&results) ///.Sort("expedition")
	if err != nil {
		log.Printf("Error calling for AllExpeditions: %v", err)
	}

	ht, err := template.New("some template").ParseFiles("templates/expeditionsAll_new.html")
	if err != nil {
		log.Printf("template parse failed: %s", err)
	}

	err = ht.ExecuteTemplate(w, "T", results)
	if err != nil {
		log.Printf("htemplate execution failed: %s", err)
	}

}
示例#3
0
// Render A document view function
// Note NOT being used ...
// called from main for measurement view  (need to FIX THIS)
// not sure if I want a M/L/S/H URL open or not at this time...
func Render(w http.ResponseWriter, r *http.Request) {
	session, err := services.GetMongoCon()
	if err != nil {
		panic(err)
	}

	defer session.Close()

	// Optional. Switch the session to a monotonic behavior.
	session.SetMode(mgo.Monotonic, true)
	c := session.DB("test").C("uniqueids")

	// Steps:   convert URL to URI and then go looking up the datasets

	// This is where I use the structs from ocdJanus
	URL := "http://opencoredata.org/doc/dataset/JanusAgeDatapoint/108/668/B"
	result := Uriurl{}
	err = c.Find(bson.M{"url": URL}).One(&result)
	if err != nil {
		log.Printf("URL lookup error: %v", err)
	}

	log.Printf("doc:  %s", r.URL.Path)

	w.Header().Set("Content-type", "text/plain")
	fmt.Fprintf(w, "%s", result.Uri)
}
示例#4
0
// need to return an error too
func GetDatasets(Leg string, Site string) []SchemaOrgMetadata {
	session, err := services.GetMongoCon()
	if err != nil {
		panic(err)
	}
	defer session.Close()

	// Optional. Switch the session to a monotonic behavior.
	session.SetMode(mgo.Monotonic, true)
	c := session.DB("test").C("schemaorg")

	var results []SchemaOrgMetadata

	switch Site {
	case "":
		err = c.Find(bson.M{"opencoreleg": Leg}).All(&results)
	default:
		err = c.Find(bson.M{"opencoreleg": Leg, "opencoresite": Site}).All(&results)

	}

	if err != nil {
		log.Printf("Error calling for ShowExpeditions: %v", err)
		results = nil
	}

	return results

}
示例#5
0
func CSDCOcollection(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)

	session, err := services.GetMongoCon()
	if err != nil {
		panic(err)
	}
	defer session.Close()

	// Optional. Switch the session to a monotonic behavior.
	session.SetMode(mgo.Monotonic, true)
	c := session.DB("test").C("csdco")

	var results CSDCO
	err = c.Find(bson.M{"holeid": vars["HoleID"]}).One(&results)
	if err != nil {
		log.Printf("Error calling csdco : %v", err)
	}

	log.Print(vars["HoleID"])
	log.Print(results)

	ht, err := template.New("some template").ParseFiles("templates/catalog_csdco_new.html") //open and parse a template text file
	if err != nil {
		log.Printf("template parse failed: %s", err)
	}

	err = ht.ExecuteTemplate(w, "T", results) //substitute fields in the template 't', with values from 'user' and write it out to 'w' which implements io.Writer
	if err != nil {
		log.Printf("htemplate execution failed: %s", err)
	}

}
示例#6
0
// MesSets is for sets of measurements
func MesSets(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)

	// call mongo and lookup the redirection to use...
	session, err := services.GetMongoCon()
	if err != nil {
		panic(err)
	}
	defer session.Close()

	// Optional. Switch the session to a monotonic behavior.
	session.SetMode(mgo.Monotonic, true)
	c := session.DB("test").C("aggregation_janusURLSet")

	var results []URLSet
	err = c.Find(bson.M{"measure": vars["measurements"]}).All(&results)
	if err != nil {
		log.Printf("Error calling aggregation_janusURLSet: in MesSet %v", err)
	}

	// log.Print(results)
	// need to build simple metadata package around schema.org/DataCatalog
	authorInfo := SchemaAuthor{Type: "Organization", Name: "Joides Resolution Science Office",
		URL: "http://iodp.org", Description: "NSF funded operator for International Ocean Discvery Project"}
	dataSets := []ShemaDataset{}
	for _, dp := range results {
		for _, d := range dp.Refdata {
			dataSet := ShemaDataset{Type: "Dataset", URL: d.Url}
			dataSets = append(dataSets, dataSet)
		}
	}
	dataCatalog := SchemaDatacatalog{Context: "http://schema.org",
		Type:        "DataCatalog",
		Author:      authorInfo,
		Dataset:     dataSets,
		Description: fmt.Sprintf("Data set for measurement %s ", vars["measurements"]),
		Name:        fmt.Sprintf("%s", vars["measurements"]),
		URL:         fmt.Sprintf("http://opencoredata.org/collections/measurement/%s", vars["measurements"])}

	schematext, _ := json.Marshal(dataCatalog) // .MarshalIndent(dataCatalog, "", " ")

	data := TemplateForMeasurement{URLdata: results, Schema: string(schematext), Measure: vars["measurements"]}

	ht, err := template.New("some template").ParseFiles("templates/jrso_M_new.html") //open and parse a template text file
	if err != nil {
		log.Printf("template parse failed: %s", err)
	}

	// tmpl.Execute(out, template.HTML(`<b>World</b>`))

	err = ht.ExecuteTemplate(w, "T", data) //substitute fields in the template 't', with values from 'user' and write it out to 'w' which implements io.Writer
	if err != nil {
		log.Printf("htemplate execution failed: %s", err)
	}
}
示例#7
0
//ShowExpedition is the handler for URL patterns: http://localhost/doc/expedition/28
func ShowExpedition(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)

	session, err := services.GetMongoCon()
	if err != nil {
		panic(err)
	}
	defer session.Close()

	// Optional. Switch the session to a monotonic behavior.
	session.SetMode(mgo.Monotonic, true)
	c := session.DB("expedire").C("expeditions")

	EXPEDITION := vars["LEG"]
	var results CruiseGL
	err = c.Find(bson.M{"expedition": EXPEDITION}).One(&results)
	if err != nil {
		log.Printf("Error calling for ShowExpeditions: %v", err)
	}

	// TODO  FIX!   The next 10 lines are hideous and should not need to be here.
	// I am stripping the trailing / that is in the graph data.
	// These slices are hideous..  some have trailing /'s that alter resolution
	lshSlice := strings.Split(results.Legsitehole, " ")

	// For each string in this slice need to check and remove any trailing /
	for k, _ := range lshSlice {
		if last := len(lshSlice[k]) - 1; last >= 0 && lshSlice[k][last] == '/' {
			lshSlice[k] = lshSlice[k][:last]
		}
	}

	// Make a new struct and put results and lshslice into it and pass it along
	type TemplateStruct struct {
		Cruise   CruiseGL
		LSHSlice []string
		Datasets []SchemaOrgMetadata
	}

	SendToTemplate := TemplateStruct{Cruise: results, LSHSlice: lshSlice, Datasets: GetDatasets(EXPEDITION, "")}

	ht, err := template.New("some template").ParseFiles("templates/expedition_new.html")
	if err != nil {
		log.Printf("template parse failed: %s", err)
	}

	err = ht.ExecuteTemplate(w, "T", SendToTemplate)
	if err != nil {
		log.Printf("htemplate execution failed: %s", err)
	}
}
示例#8
0
func ShowFeature(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)

	// call mongo and lookup the redirection to use...
	session, err := services.GetMongoCon()
	if err != nil {
		panic(err)
	}
	defer session.Close()

	// Optional. Switch the session to a monotonic behavior.
	session.SetMode(mgo.Monotonic, true)
	c := session.DB("expedire").C("features")

	// test for HOLE (not in all DSDP sites)
	var URI string
	_, ok := vars["HOLE"]
	if ok == true {
		URI = fmt.Sprintf("http://opencoredata.org/id/expedition/%s/%s/%s", vars["LEG"], vars["SITE"], vars["HOLE"])
	} else {
		URI = fmt.Sprintf("http://opencoredata.org/id/expedition/%s/%s", vars["LEG"], vars["SITE"])
	}

	result := Feature{}
	err = c.Find(bson.M{"uri": URI}).One(&result)
	if err != nil {
		log.Printf("ShowFeature URI lookup error: %v %v", err, vars)
	}
	jsonldtext, _ := json.MarshalIndent(result, "", " ") // results as embeddale JSON-LD

	ht, err := template.New("some template").ParseFiles("templates/feature_new.html")
	if err != nil {
		log.Printf("template parse failed: %s", err)
	}

	dataForTemplate := DataForTemplate{Schema: result, SchemaString: string(jsonldtext), Datasets: GetDatasets(vars["LEG"], vars["SITE"])}

	err = ht.ExecuteTemplate(w, "T", dataForTemplate)
	if err != nil {
		log.Printf("htemplate execution failed: %s", err)
	}

}