From aa985a94c22c1b01648078dc2a767a479263fba5 Mon Sep 17 00:00:00 2001
From: LoLo5689 <lorenzotheunissen@gmail.com>
Date: Wed, 16 Jun 2021 13:45:26 +0200
Subject: [PATCH] comments

Co-authored-by: Chris <CrispyBaconz@users.noreply.github.com>
---
 aql/convertQuery.go               | 47 ++++++++++---------
 aql/convertQueryBenchmark_test.go | 17 +++++++
 aql/convertQuery_test.go          | 78 +++++++++++++++++++++++++++++++
 aql/mockConvertQuery.go           | 24 ++++++++--
 cypher/convertQuery.go            | 46 +++++++++++-------
 cypher/queryConverter.go          | 14 +++++-
 main/main.go                      |  8 ++++
 7 files changed, 191 insertions(+), 43 deletions(-)

diff --git a/aql/convertQuery.go b/aql/convertQuery.go
index af21018..87d4a01 100644
--- a/aql/convertQuery.go
+++ b/aql/convertQuery.go
@@ -1,3 +1,8 @@
+/*
+This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course.
+© Copyright Utrecht University (Department of Information and Computing Sciences)
+*/
+
 package aql
 
 import (
@@ -48,10 +53,10 @@ func (s *Service) ConvertQuery(JSONQuery *entity.IncomingQueryJSON) (*string, er
 	return result, nil
 }
 
-/* createQuery generates a query based on the json file provided
-Parameters: jsonQuery is a parsedJSON struct holding all the data needed to form a query
-
-Return: a string containing the corresponding AQL query and an error
+/*
+createQuery generates a query based on the json file provided
+	JSONQuery: *entity.IncomingQueryJSON, this is a parsedJSON struct holding all the data needed to form a query,
+	Return: *string, a string containing the corresponding AQL query and an error
 */
 func createQuery(JSONQuery *entity.IncomingQueryJSON) *string {
 	// Note: Case #4, where there is an edge only query (without any entity), is not supported by frontend
@@ -246,11 +251,11 @@ func createQuery(JSONQuery *entity.IncomingQueryJSON) *string {
 	return &ret
 }
 
-/* createNodeLet generates a 'LET' statement for a node related query
-Parameters: node is an entityStruct containing the information of a single node,
-name is the autogenerated name of the node consisting of "n" + the index of the node
-
-Return: a string containing a single LET-statement in AQL
+/*
+createNodeLet generates a 'LET' statement for a node related query
+	node: *entity.QueryEntityStruct, node is an entityStruct containing the information of a single nod,
+	name: *string, is the autogenerated name of the node consisting of "n" + the index of the node,
+	Return: *string, a string containing a single LET-statement in AQL
 */
 func createNodeLet(node *entity.QueryEntityStruct, name *string) *string {
 	header := fmt.Sprintf("LET %v = (\n\tFOR x IN %v \n", *name, node.Type)
@@ -261,12 +266,12 @@ func createNodeLet(node *entity.QueryEntityStruct, name *string) *string {
 	return &ret
 }
 
-/* createRelationLetWithFromEntity generates a 'LET' statement for relations with an 'EntityFrom' property and optionally an 'EntitiyTo' property
-Parameters: relation is a relation struct containing the information of a single relation,
-name is the autogenerated name of the node consisting of "r" + the index of the relation,
-entities is a list of entityStructs that are needed to form the relation LET-statement
-
-Return: a string containing a single LET-statement in AQL
+/*
+createRelationLetWithFromEntity generates a 'LET' statement for relations with an 'EntityFrom' property and optionally an 'EntitiyTo' property
+	relation: *entity.QueryRekationStruct, relation is a relation struct containing the information of a single relation,
+	name: string, is the autogenerated name of the node consisting of "r" + the index of the relation,
+	entities: *[]entity.QueryEntityStrucy, is a list of entityStructs that are needed to form the relation LET-statement,
+	Return: *string, a string containing a single LET-statement in AQL
 */
 func createRelationLetWithFromEntity(relation *entity.QueryRelationStruct, name string, entities *[]entity.QueryEntityStruct, limit int) *string {
 	header := fmt.Sprintf("LET %v = (\n\tFOR x IN n%v \n", name, relation.EntityFrom)
@@ -296,12 +301,12 @@ func createRelationLetWithFromEntity(relation *entity.QueryRelationStruct, name
 	return &ret
 }
 
-/* createRelationLetWithOnlyToEntity generates a 'LET' statement for relations with only an 'EntityTo' property
-Parameters: relation is a relation struct containing the information of a single relation,
-name is the autogenerated name of the node consisting of "r" + the index of the relation,
-entities is a list of entityStructs that are needed to form the relation LET-statement
-
-Return: a string containing a single LET-statement in AQL
+/*
+createRelationLetWithOnlyToEntity generates a 'LET' statement for relations with only an 'EntityTo' property
+	relation: *entity.QueryRelationStruct, relation is a relation struct containing the information of a single relation,
+	name: string, is the autogenerated name of the node consisting of "r" + the index of the relation,
+	entities: *[]entity.QueryEntityStruct, is a list of entityStructs that are needed to form the relation LET-statement,
+	Return: *string, a string containing a single LET-statement in AQL
 */
 func createRelationLetWithOnlyToEntity(relation *entity.QueryRelationStruct, name string, entities *[]entity.QueryEntityStruct, limit int) *string {
 	header := fmt.Sprintf("LET %v = (\n\tFOR x IN n%v \n", name, relation.EntityTo)
diff --git a/aql/convertQueryBenchmark_test.go b/aql/convertQueryBenchmark_test.go
index 6d608cd..2506fe3 100644
--- a/aql/convertQueryBenchmark_test.go
+++ b/aql/convertQueryBenchmark_test.go
@@ -1,3 +1,8 @@
+/*
+This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course.
+© Copyright Utrecht University (Department of Information and Computing Sciences)
+*/
+
 package aql
 
 import (
@@ -7,6 +12,10 @@ import (
 	"git.science.uu.nl/datastrophe/query-conversion/entity"
 )
 
+/*
+Benchmarks converting an empty query
+	t: *testing.T, makes go recognise this as a test
+*/
 func BenchmarkConvertEmptyQuery(b *testing.B) {
 	// Setup for test
 	// Create query conversion service
@@ -33,6 +42,10 @@ func BenchmarkConvertEmptyQuery(b *testing.B) {
 	}
 }
 
+/*
+Benchmarks converting a one attribute query
+	t: *testing.T, makes go recognise this as a test
+*/
 func BenchmarkConvertOneAttributeQuery(b *testing.B) {
 	// Setup for test
 	// Create query conversion service
@@ -73,6 +86,10 @@ func BenchmarkConvertOneAttributeQuery(b *testing.B) {
 	}
 }
 
+/*
+Benchmarks converting a two relation query
+	t: *testing.T, makes go recognise this as a test
+*/
 func BenchmarkConvertTwoRelationQuery(b *testing.B) {
 	// Setup for test
 	// Create query conversion service
diff --git a/aql/convertQuery_test.go b/aql/convertQuery_test.go
index 0ab5490..65c8918 100644
--- a/aql/convertQuery_test.go
+++ b/aql/convertQuery_test.go
@@ -1,3 +1,8 @@
+/*
+This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course.
+© Copyright Utrecht University (Department of Information and Computing Sciences)
+*/
+
 package aql
 
 import (
@@ -10,6 +15,10 @@ import (
 	"github.com/stretchr/testify/assert"
 )
 
+/*
+Tests an empty query
+	t: *testing.T, makes go recognise this as a test
+*/
 func TestEmptyQueryConversion(t *testing.T) {
 	// Setup for test
 	// Create query conversion service
@@ -41,6 +50,11 @@ LET edges = first(RETURN UNION_DISTINCT([],[]))
 RETURN {"vertices":nodes, "edges":edges }`
 	assert.Equal(t, correctConvertedResult, *convertedResult)
 }
+
+/*
+Tests multiple entity types
+	t: *testing.T, makes go recognise this as a test
+*/
 func TestMultipleEntityTypes(t *testing.T) {
 	// Setup for test
 	// Create query conversion service
@@ -116,6 +130,10 @@ func TestMultipleEntityTypes(t *testing.T) {
 	assert.Equal(t, convertedCleanedResult, cleanedResult)
 }
 
+/*
+Tests a query with one attribute
+	t: *testing.T, makes go recognise this as a test
+*/
 func TestEntityOneAttributeQuery(t *testing.T) {
 	// Setup for test
 	// Create query conversion service
@@ -161,6 +179,10 @@ func TestEntityOneAttributeQuery(t *testing.T) {
 	assert.Equal(t, correctConvertedResult, cleanedResult)
 }
 
+/*
+Test a relation with a constraint
+	t: *testing.T, makes go recognise this as a test
+*/
 func TestRelationWithConstraint(t *testing.T) {
 	// Setup for test
 	// Create query conversion service
@@ -226,6 +248,10 @@ func TestRelationWithConstraint(t *testing.T) {
 	assert.Equal(t, correctConvertedResult, cleanedResult)
 }
 
+/*
+Tests the count modifier
+	t: *testing.T, makes go recognise this as a test
+*/
 func TestModifierCountEntity(t *testing.T) {
 	// Setup for test
 	// Create query conversion service
@@ -278,6 +304,11 @@ func TestModifierCountEntity(t *testing.T) {
 	cleanedResult = strings.ReplaceAll(cleanedResult, "\t", "")
 	assert.Equal(t, correctConvertedResult, cleanedResult)
 }
+
+/*
+Tests the count modifer with an attribute
+	t: *testing.T, makes go recognise this as a test
+*/
 func TestModifierCountEntityAttribute(t *testing.T) {
 	// Setup for test
 	// Create query conversion service
@@ -330,6 +361,11 @@ func TestModifierCountEntityAttribute(t *testing.T) {
 	cleanedResult = strings.ReplaceAll(cleanedResult, "\t", "")
 	assert.Equal(t, correctConvertedResult, cleanedResult)
 }
+
+/*
+Tests the count modifier on a relation
+	t: *testing.T, makes go recognise this as a test
+*/
 func TestModifierCountRelation(t *testing.T) {
 	// Setup for test
 	// Create query conversion service
@@ -402,6 +438,11 @@ func TestModifierCountRelation(t *testing.T) {
 	cleanedResult = strings.ReplaceAll(cleanedResult, "\t", "")
 	assert.Equal(t, correctConvertedResult, cleanedResult)
 }
+
+/*
+Tests the count modifier with an entity swap
+	t: *testing.T, makes go recognise this as a test
+*/
 func TestModifierCountEntitySwap(t *testing.T) {
 	// Setup for test
 	// Create query conversion service
@@ -465,6 +506,11 @@ func TestModifierCountEntitySwap(t *testing.T) {
 	cleanedResult = strings.ReplaceAll(cleanedResult, "\t", "")
 	assert.Equal(t, correctConvertedResult, cleanedResult)
 }
+
+/*
+Tests the count modifier on a relation and attribute
+	t: *testing.T, makes go recognise this as a test
+*/
 func TestModifierCountRelationAttribute(t *testing.T) {
 	// Setup for test
 	// Create query conversion service
@@ -538,6 +584,10 @@ func TestModifierCountRelationAttribute(t *testing.T) {
 	assert.Equal(t, correctConvertedResult, cleanedResult)
 }
 
+/*
+Tests a relation with an in out constraint
+	t: *testing.T, makes go recognise this as a test
+*/
 func TestRelationWithInOutConstraint(t *testing.T) {
 	// Setup for test
 	// Create query conversion service
@@ -615,6 +665,10 @@ func TestRelationWithInOutConstraint(t *testing.T) {
 	assert.Equal(t, correctConvertedResult, cleanedResult)
 }
 
+/*
+Tests two relations
+	t: *testing.T, makes go recognise this as a test
+*/
 func TestTwoRelations(t *testing.T) {
 	// Setup for test
 	// Create query conversion service
@@ -715,6 +769,10 @@ func TestTwoRelations(t *testing.T) {
 	assert.Equal(t, correctConvertedResult, cleanedResult)
 }
 
+/*
+Tests a relation with only a to node
+	t: *testing.T, makes go recognise this as a test
+*/
 func TestRelationWithOnlyToNode(t *testing.T) {
 	// Setup for test
 	// Create query conversion service
@@ -773,6 +831,10 @@ func TestRelationWithOnlyToNode(t *testing.T) {
 	assert.Equal(t, correctConvertedResult, cleanedResult)
 }
 
+/*
+Tests too manu return entities
+	t: *testing.T, makes go recognise this as a test
+*/
 func TestTooManyReturnEntities(t *testing.T) {
 	// Setup for test
 	// Create query conversion service
@@ -827,6 +889,10 @@ func TestTooManyReturnEntities(t *testing.T) {
 	assert.Equal(t, errors.New("non-existing entity referenced in return"), err)
 }
 
+/*
+Tests too manu return relations
+	t: *testing.T, makes go recognise this as a test
+*/
 func TestTooManyReturnRelations(t *testing.T) {
 	// Setup for test
 	// Create query conversion service
@@ -881,6 +947,10 @@ func TestTooManyReturnRelations(t *testing.T) {
 	assert.Equal(t, errors.New("non-existing relation referenced in return"), err)
 }
 
+/*
+Tests negative return entities
+	t: *testing.T, makes go recognise this as a test
+*/
 func TestNegativeReturnEntities(t *testing.T) {
 	// Setup for test
 	// Create query conversion service
@@ -936,6 +1006,10 @@ func TestNegativeReturnEntities(t *testing.T) {
 	assert.Equal(t, errors.New("non-existing entity referenced in return"), err)
 }
 
+/*
+Tests a query with no relation field
+	t: *testing.T, makes go recognise this as a test
+*/
 func TestNoRelationsField(t *testing.T) {
 	// Setup for test
 	// Create query conversion service
@@ -979,6 +1053,10 @@ func TestNoRelationsField(t *testing.T) {
 	assert.Equal(t, correctConvertedResult, cleanedResult)
 }
 
+/*
+Tests an entity with a lower than -1 in a relation
+	t: *testing.T, makes go recognise this as a test
+*/
 func TestEntityFromLowerThanNegativeOneInRelation(t *testing.T) {
 	// Setup for test
 	// Create query conversion service
diff --git a/aql/mockConvertQuery.go b/aql/mockConvertQuery.go
index 3c0ffbf..5f82c69 100644
--- a/aql/mockConvertQuery.go
+++ b/aql/mockConvertQuery.go
@@ -1,3 +1,8 @@
+/*
+This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course.
+© Copyright Utrecht University (Department of Information and Computing Sciences)
+*/
+
 package aql
 
 import (
@@ -6,19 +11,28 @@ import (
 	"git.science.uu.nl/datastrophe/query-conversion/entity"
 )
 
-// A MockService implements the query convert usecase interface (mock)
+/*
+A MockService implements the query convert usecase interface (mock)
+*/
 type MockService struct {
 	throwError bool
 }
 
-// NewMockService creates a new query convert service (mock)
+/*
+NewMockService creates a new query convert service (mock)
+	Return: *MockService, returns a mock service
+*/
 func NewMockService() *MockService {
 	return &MockService{
 		throwError: false,
 	}
 }
 
-// ConvertQuery returns a hard coded string message (mock)
+/*
+ConvertQuery returns a hard coded string message (mock)
+	JSONQuer: *entity.IncomingQueryJSON, the incoming query in JSON format
+	Return: (*string, error), the result and a potential error
+*/
 func (s *MockService) ConvertQuery(JSONQuery *entity.IncomingQueryJSON) (*string, error) {
 	mockQuery := "Query converted"
 
@@ -28,7 +42,9 @@ func (s *MockService) ConvertQuery(JSONQuery *entity.IncomingQueryJSON) (*string
 	return nil, errors.New("Failed to convert query")
 }
 
-// ToggleError decides whether the convert function throws an error
+/*
+ToggleError decides whether the convert function throws an error
+*/
 func (s *MockService) ToggleError() {
 	s.throwError = !s.throwError
 }
diff --git a/cypher/convertQuery.go b/cypher/convertQuery.go
index cd869cb..3a89ec8 100644
--- a/cypher/convertQuery.go
+++ b/cypher/convertQuery.go
@@ -1,3 +1,8 @@
+/*
+This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course.
+© Copyright Utrecht University (Department of Information and Computing Sciences)
+*/
+
 package cypher
 
 import (
@@ -11,7 +16,7 @@ import (
 /*
 ConvertQuery converts an IncomingQueryJSON object into AQL
 	JSONQuery: *entity.IncomingQueryJSON, the query to be converted to AQL
-	Returns: *string, the AQL query and a possible error
+	Returns: (*string, error), the AQL query and a possible error
 */
 func (s *Service) ConvertQuery(JSONQuery *entity.IncomingQueryJSON) (*string, error) {
 
@@ -47,6 +52,12 @@ func (s *Service) ConvertQuery(JSONQuery *entity.IncomingQueryJSON) (*string, er
 	return result, nil
 }
 
+/*
+sliceContains checks if a slice contains the input
+	s: []int, the slice to check
+	e: int, what you're checking for
+	Return: bool, true if it contains 'e'
+*/
 func sliceContains(s []int, e int) bool {
 	for _, a := range s {
 		if a == e {
@@ -64,10 +75,10 @@ func TrimSuffix(s, suffix string) string {
 	return s
 }
 
-/* createQuery generates a query based on the json file provided
-Parameters: jsonQuery is a parsedJSON struct holding all the data needed to form a query
-
-Return: a string containing the corresponding AQL query and an error
+/*
+createQuery generates a query based on the json file provided
+	JSONQuery: *entity.IncomingQueryJSON, jsonQuery is a parsedJSON struct holding all the data needed to form a query
+	Return: *string, a string containing the corresponding AQL query and an error
 */
 func createQuery(JSONQuery *entity.IncomingQueryJSON) *string {
 	// Note: Case #4, where there is an edge only query (without any entity), is not supported by frontend
@@ -183,11 +194,11 @@ func createQuery(JSONQuery *entity.IncomingQueryJSON) *string {
 	return &ret
 }
 
-/* createNodeLet generates a 'LET' statement for a node related query
-Parameters: node is an entityStruct containing the information of a single node,
-name is the autogenerated name of the node consisting of "n" + the index of the node
-
-Return: a string containing a single LET-statement in AQL
+/*
+createNodeLet generates a 'LET' statement for a node related query
+	node: *entity.QueryEntityStruct, node is an entityStruct containing the information of a single node,
+	name: *string, is the autogenerated name of the node consisting of "n" + the index of the node
+	Return: *string, a string containing a single LET-statement in AQL
 */
 func createNodeMatch(node *entity.QueryEntityStruct, name *string) *string {
 	// hier zat een newline
@@ -197,12 +208,15 @@ func createNodeMatch(node *entity.QueryEntityStruct, name *string) *string {
 	return &ret
 }
 
-/* createRelationLetWithFromEntity generates a 'LET' statement for relations with an 'EntityFrom' property and optionally an 'EntitiyTo' property
-Parameters: relation is a relation struct containing the information of a single relation,
-name is the autogenerated name of the node consisting of "r" + the index of the relation,
-entities is a list of entityStructs that are needed to form the relation LET-statement
-
-Return: a string containing a single LET-statement in AQL
+/*
+createRelationLetWithFromEntity generates a 'LET' statement for relations with an 'EntityFrom' property and optionally an 'EntitiyTo' property
+	relation: *entity.QueryRelationStruct, relation is a relation struct containing the information of a single relation,
+	relationName: string, is the name of the relation, is the autogenerated name of the node consisting of "r" + the index of the relation,
+	pathName: string, is the path of the name,
+	entities: *[]entity.QueryEntityStruct, is a list of entityStructs that are needed to form the relation LET-statement
+	limit: int, the limit for the number of nodes to return
+	outbound: bool, checks if the relation is inbound or outbound
+	Return: *string, a string containing a single LET-statement in AQL
 */
 func createRelationMatch(relation *entity.QueryRelationStruct, relationName string, pathName string, entities *[]entity.QueryEntityStruct, limit int, outbound bool) *string {
 	relationReturn := ""
diff --git a/cypher/queryConverter.go b/cypher/queryConverter.go
index 1b0536f..70967b8 100644
--- a/cypher/queryConverter.go
+++ b/cypher/queryConverter.go
@@ -1,10 +1,20 @@
+/*
+This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course.
+© Copyright Utrecht University (Department of Information and Computing Sciences)
+*/
+
 package cypher
 
-// Service implements the QueryConverter interface (in the query service)
+/*
+Service implements the QueryConverter interface (in the query service)
+*/
 type Service struct {
 }
 
-// NewService creates a new AQL conversion service
+/*
+NewService creates a new AQL conversion service
+	Return: *Service, the new service
+*/
 func NewService() *Service {
 	return &Service{}
 }
diff --git a/main/main.go b/main/main.go
index dfb886b..b2c863a 100644
--- a/main/main.go
+++ b/main/main.go
@@ -1,3 +1,8 @@
+/*
+This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course.
+© Copyright Utrecht University (Department of Information and Computing Sciences)
+*/
+
 package main
 
 import (
@@ -8,6 +13,9 @@ import (
 	"git.science.uu.nl/datastrophe/query-conversion/entity"
 )
 
+/*
+The main function that calls the appropriate functions
+*/
 func main() {
 	queryservice := cypher.NewService()
 
-- 
GitLab