Skip to content

Commit

Permalink
Merge pull request #9 from cristian-sima/improve-harvesting
Browse files Browse the repository at this point in the history
Improve harvesting
  • Loading branch information
cristian-sima committed Oct 6, 2015
2 parents 9c74a8c + 0f04ace commit a11e839
Show file tree
Hide file tree
Showing 143 changed files with 15,546 additions and 1,755 deletions.
1 change: 1 addition & 0 deletions controllers/admin/Account.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type AccountController struct {
func (controller *AccountController) List() {
accounts := controller.model.GetAllAccounts()
controller.Data["accounts"] = accounts
controller.SetCustomTitle("Admin - Accounts")
controller.TplNames = "site/admin/account/list.tpl"
}

Expand Down
1 change: 1 addition & 0 deletions controllers/admin/Admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func (controller *Controller) DisplayDashboard() {
controller.Data["numberOfAccounts"] = dashboard.Accounts
controller.Data["numberOfRepositories"] = dashboard.Repositories
controller.TplNames = "site/admin/admin/dashboard.tpl"
controller.SetCustomTitle("Admin - Dashboard")
}

// Prepare redirects to a login page in case the account is not connected, else it loads the page
Expand Down
51 changes: 36 additions & 15 deletions controllers/admin/Harvest.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"strconv"

event "github.com/cristian-sima/Wisply/models/event"
harvest "github.com/cristian-sima/Wisply/models/harvest"
repository "github.com/cristian-sima/Wisply/models/repository"
ws "github.com/cristian-sima/Wisply/models/ws"
Expand All @@ -17,7 +18,7 @@ var CurrentProcesses = make(map[int]*Process)
// Process contians information about a process
type Process struct {
Connections []*ws.Connection `json:"-"`
Manager *harvest.Manager `json:"-"`
Process *harvest.Process `json:"Manager"`
}

func (process *Process) addConnection(connection *ws.Connection) {
Expand All @@ -32,7 +33,8 @@ func init() {
// HarvestController manages the operations for repository (list, delete, add)
type HarvestController struct {
Controller
Model repository.Model
Model repository.Model
EventManager event.Manager
}

// InitWebsocketConnection initiats the websocket connection
Expand Down Expand Up @@ -118,36 +120,34 @@ func (controller *HarvestController) StartProcess(message *ws.Message, connectio
ID := message.Repository
delete(CurrentProcesses, ID)

harvestManager := harvest.NewManager(strconv.Itoa(ID), controller)
harvestProcess := harvest.NewProcess(strconv.Itoa(ID), controller)
process := &Process{
Manager: harvestManager,
Process: harvestProcess,
}
process.addConnection(connection)
CurrentProcesses[ID] = process
harvestManager.StartProcess()
harvestProcess.Start()
}
}

// Notify is called by a harvest repository with a message
func (controller *HarvestController) Notify(message *harvest.Message) {
process, ok := CurrentProcesses[message.Repository]

fmt.Println("<--> Harvest Controller: The controller has received this message:")
controller.log("The controller has received this message:")
fmt.Println(message)
if ok {
switch message.Name {
case "status-changed", "identification-details":
case "status-changed", "identification-details", "event-notice":
{
msg := ConvertToWebsocketMessage(message)
hub.BroadcastMessage(msg)
}
break
case "verification-finished":
if message.Value == "failed" {
msg := ConvertToWebsocketMessage(message)
hub.SendGroupMessage(msg, process.Connections)
delete(CurrentProcesses, message.Repository)
}
case "harvesting", "verification-finished":
msg := ConvertToWebsocketMessage(message)
hub.SendGroupMessage(msg, process.Connections)
break
case "delete-process":
{
delete(CurrentProcesses, message.Repository)
Expand All @@ -169,12 +169,26 @@ func ConvertToWebsocketMessage(old *harvest.Message) *ws.Message {

// GetProcess sends the current process on the server for a repository
func (controller *HarvestController) GetProcess(message *ws.Message, connection *ws.Connection) {
processObject, _ := CurrentProcesses[message.Repository]
controller.log("Yes it goes")
process, processExists := CurrentProcesses[message.Repository]
if !processExists {
controller.log("I do not have any process for " + strconv.Itoa(message.Repository))
} else {
controller.log("I have a process for the repository " + strconv.Itoa(message.Repository))
controller.log("I add a new connection for the repository " + strconv.Itoa(message.Repository) + " process")
process.addConnection(connection)
fmt.Println(process)
}
hub.SendMessage(&ws.Message{
Name: "existing-process-on-server",
Value: &processObject,
Value: &process,
Repository: message.Repository,
}, connection)

}

func (controller *HarvestController) log(message string) {
fmt.Println("<--> Harvest Controller: " + message)
}

// SendAllRepositoriesStatus gets all repositories' status only and sends them to a connection
Expand All @@ -185,3 +199,10 @@ func (controller *HarvestController) SendAllRepositoriesStatus(connection *ws.Co
Value: &list,
}, connection)
}

// ShowEventLog displays the last events for harvesting
func (controller *HarvestController) ShowEventLog() {
controller.Data["events"] = controller.EventManager.GetLastEvents()
controller.SetCustomTitle("Admin - Event Log")
controller.TplNames = "site/admin/harvest/event-log.tpl"
}
45 changes: 35 additions & 10 deletions controllers/admin/Institution.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ func (controller *InstitutionController) DisplayAll() {
exists = (len(list) != 0)
controller.Data["anything"] = exists
controller.Data["institutions"] = list
controller.SetCustomTitle("Admin - Institutions")
controller.TplNames = "site/admin/institution/list.tpl"
controller.Layout = "site/admin-layout.tpl"
}

// Add shows the form to add an institution
func (controller *InstitutionController) Add() {
controller.SetCustomTitle("Add Institution")
controller.showAddForm()
}

Expand All @@ -31,8 +33,15 @@ func (controller *InstitutionController) Insert() {

institutionDetails := make(map[string]interface{})
institutionDetails["name"] = strings.TrimSpace(controller.GetString("institution-name"))
institutionDetails["description"] = strings.TrimSpace(controller.GetString("institution-description"))
description := controller.GetString("institution-description")

// jquery has a problem with \r
institutionDetails["description"] = strings.TrimSpace(strings.Replace(description, "\r", "", -1))

institutionDetails["url"] = strings.TrimSpace(controller.GetString("institution-URL"))
institutionDetails["logoURL"] = strings.TrimSpace(controller.GetString("institution-logoURL"))
institutionDetails["wikiURL"] = strings.TrimSpace(controller.GetString("institution-wikiURL"))
institutionDetails["wikiID"] = strings.TrimSpace(controller.GetString("institution-wikiID"))

problems, err := controller.model.InsertNewInstitution(institutionDetails)
if err != nil {
Expand All @@ -54,11 +63,21 @@ func (controller *InstitutionController) Modify() {
if err != nil {
controller.Abort("databaseError")
} else {
institutionDetails := map[string]string{
"Name": institution.Name,
"Description": institution.Description,
controller.Data["institution"] = institution

wikiReceive := false
if institution.WikiID == "" {
institution.WikiID = "NULL"
}
if institution.WikiID == "NULL" {
wikiReceive = false
} else {
wikiReceive = true
}
controller.showModifyForm(institutionDetails)

controller.Data["wikiID"] = institution.WikiID
controller.Data["wikiReceive"] = wikiReceive
controller.showModifyForm()
}
}

Expand All @@ -71,7 +90,14 @@ func (controller *InstitutionController) Update() {
ID = controller.Ctx.Input.Param(":id")

institutionDetails["name"] = strings.TrimSpace(controller.GetString("institution-name"))
institutionDetails["description"] = strings.TrimSpace(controller.GetString("institution-description"))
description := controller.GetString("institution-description")

// jquery has a problem with \r
institutionDetails["description"] = strings.TrimSpace(strings.Replace(description, "\r", "", -1))

institutionDetails["logoURL"] = strings.TrimSpace(controller.GetString("institution-logoURL"))
institutionDetails["wikiURL"] = strings.TrimSpace(controller.GetString("institution-wikiURL"))
institutionDetails["wikiID"] = strings.TrimSpace(controller.GetString("institution-wikiID"))

institution, err := repository.NewInstitution(ID)
if err != nil {
Expand Down Expand Up @@ -104,15 +130,14 @@ func (controller *InstitutionController) Delete() {
}
}

func (controller *InstitutionController) showModifyForm(institution map[string]string) {
controller.Data["institutionName"] = institution["Name"]
controller.Data["institutionUrl"] = institution["Url"]
controller.Data["institutionDescription"] = institution["Description"]
func (controller *InstitutionController) showModifyForm() {
controller.showForm("Modify", "Modify this institution")
}

func (controller *InstitutionController) showAddForm() {
controller.showForm("Add", "Add a new institution")
controller.Data["wikiID"] = "NULL"
controller.Data["wikiReceive"] = false
}

func (controller *InstitutionController) showForm(action string, legend string) {
Expand Down
33 changes: 32 additions & 1 deletion controllers/admin/Repository.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package admin

import (
"strconv"
"strings"

repository "github.com/cristian-sima/Wisply/models/repository"
Expand All @@ -20,12 +21,14 @@ func (controller *RepositoryController) List() {
controller.Data["anything"] = exists
controller.Data["repositories"] = list
controller.Data["host"] = controller.Ctx.Request.Host
controller.SetCustomTitle("Admin - Repositories")
controller.TplNames = "site/admin/repository/list.tpl"
}

// Add shows the form to add a new repository
func (controller *RepositoryController) Add() {
controller.Data["institutions"] = controller.model.GetAllInstitutions()
controller.SetCustomTitle("Add Repository")
controller.showAddForm()
}

Expand Down Expand Up @@ -86,7 +89,7 @@ func (controller *RepositoryController) Update() {
if err != nil {
controller.DisplayError(problems)
} else {
controller.DisplaySuccessMessage("The account has been modified!", "/admin/repositories/")
controller.DisplaySuccessMessage("The account has been modified!", "/admin/repositories/repository/"+strconv.Itoa(repository.ID))
}
}
}
Expand Down Expand Up @@ -128,3 +131,31 @@ func (controller *RepositoryController) showForm(action string, legend string) {
controller.Data["actionType"] = "POST"
controller.TplNames = "site/admin/repository/form.tpl"
}

// ShowRepository shows the administrative information regarding a repository
func (controller *RepositoryController) ShowRepository() {
ID := controller.Ctx.Input.Param(":id")
repository, err := repository.NewRepository(ID)
if err != nil {
controller.Abort("databaseError")
} else {
controller.Data["repository"] = repository
controller.Data["institution"] = repository.GetInstitution()
controller.Data["identification"] = repository.GetIdentification()
controller.TplNames = "site/admin/repository/repository.tpl"
}
}

// ShowAdvanceOptions displays the page with further options such as modify or delete
func (controller *RepositoryController) ShowAdvanceOptions() {
ID := controller.Ctx.Input.Param(":id")
repository, err := repository.NewRepository(ID)
if err != nil {
controller.Abort("databaseError")
} else {
controller.Data["repository"] = repository
controller.Data["institution"] = repository.GetInstitution()
controller.Data["identification"] = repository.GetIdentification()
controller.TplNames = "site/admin/repository/advance-options.tpl"
}
}
2 changes: 1 addition & 1 deletion controllers/general/Wisply.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (controller *WisplyController) checkConnectionCookie() {
cookieName := auth.Settings["cookieName"].(string)
cookie := controller.Ctx.GetCookie(cookieName)
if cookie != "" {
idUser, err := auth.ReConnect(cookie)
idUser, err := auth.ReconnectUsingCookie(cookie)
if err == nil {
controller.initConnectedState(idUser)
} else {
Expand Down
2 changes: 2 additions & 0 deletions controllers/public/Institution.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func (controller *InstitutionController) List() {
controller.Data["anything"] = exists
controller.Data["institutions"] = list
controller.Data["host"] = controller.Ctx.Request.Host
controller.SetCustomTitle("Institutions")
controller.TplNames = "site/public/institution/list.tpl"
controller.Layout = "site/public-layout.tpl"
}
Expand All @@ -27,6 +28,7 @@ func (controller *InstitutionController) ShowInstitution() {
if err != nil {
controller.Abort("databaseError")
} else {
controller.SetCustomTitle(institution.Name)
controller.Data["institution"] = institution
controller.Data["repositories"] = institution.GetRepositories()
controller.Layout = "site/public-layout.tpl"
Expand Down
1 change: 1 addition & 0 deletions controllers/public/Repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func (controller *RepositoryController) ShowRepository() {
if err != nil {
controller.Abort("databaseError")
} else {
controller.SetCustomTitle(rep.Name)
controller.Data["repository"] = rep
controller.Data["institution"] = institution
controller.Data["identification"] = identification
Expand Down
4 changes: 2 additions & 2 deletions controllers/public/Static.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (controller *StaticController) ShowPrivacyPolicy() {
pageName := "privacy"
controller.showStaticPage(pageName)

controller.SetCustomTitle("Wisply Privicy Policy")
controller.SetCustomTitle("Wisply Privacy Policy")
controller.IndicateLastModification(1442660323)
}

Expand All @@ -74,7 +74,7 @@ func (controller *StaticController) ShowCookiesPolicy() {
pageName := "cookies"
controller.showStaticPage(pageName)

controller.SetCustomTitle("Wisply Cookie Policy")
controller.SetCustomTitle("Wisply Cookies Policy")
controller.IndicateLastModification(1442660323)
}

Expand Down
Loading

0 comments on commit a11e839

Please sign in to comment.