Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Base script class extended by all Groovy action scripts.
* Provides common utility functions for Groovy actions.
*/
abstract class BaseScript extends Script {

/**
* Example utility function that could be used by Groovy actions
*/
def utilityFunction(String value) {
return "processed: " + value
}

/**
* Helper method to log debug messages
*/
def debug(String message) {
logger.debug(message)
}

/**
* Helper method to log info messages
*/
def info(String message) {
logger.info(message)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"actions": [
{
"name": "predefinedAction",
"script": "import org.apache.unomi.groovy.actions.annotations.Action\n@Action(id = \"predefinedAction\", name = \"Predefined Action\")\ndef execute() {\n logger.info(\"Executing predefined action\")\n return true\n}"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import org.apache.unomi.groovy.actions.annotations.Action
import org.apache.unomi.groovy.actions.annotations.Parameter

/**
* Test Groovy action for unit tests
*/
@Action(
id = "testAction",
name = "Test Action",
description = "A test action for unit testing",
parameters = [
@Parameter(id = "param1", type = "string"),
@Parameter(id = "param2", type = "integer")
]
)
def execute() {
logger.info("Executing test action")

// Use base script utility function
def processedText = utilityFunction("test")
logger.debug("Processed text: ${processedText}")

return true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import org.apache.unomi.api.services.EventService
import org.apache.unomi.groovy.actions.annotations.Action
import org.apache.unomi.groovy.actions.annotations.Parameter

/**
* Test Groovy action that accepts parameters and returns EventService constants
*/
@Action(
id = "testExecuteAction",
name = "Test Execute Action",
description = "Action for testing execution with parameters",
actionExecutor = "groovy:testExecuteAction",
parameters = [
@Parameter(id = "returnType", type = "string", multivalued = false),
@Parameter(id = "shouldFail", type = "boolean", multivalued = false)
]
)
def execute() {
// Access parameters from the action object
def returnType = action.getParameterValues().get("returnType")
def shouldFail = action.getParameterValues().get("shouldFail")

// Log received parameters
logger.info("Executing action with parameters: returnType=${returnType}, shouldFail=${shouldFail}")

// Check the should fail parameter
if (shouldFail) {
logger.error("Action execution failed as requested by shouldFail parameter")
return EventService.ERROR
}

// Return based on the returnType parameter
switch (returnType) {
case "SESSION_UPDATED":
return EventService.SESSION_UPDATED
case "NO_CHANGE":
return EventService.NO_CHANGE
default:
logger.warn("Unknown returnType: ${returnType}, defaulting to NO_CHANGE")
return EventService.NO_CHANGE
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import org.apache.unomi.api.services.EventService
import org.apache.unomi.groovy.actions.annotations.Action
import org.apache.unomi.groovy.actions.annotations.Parameter

/**
* Test Groovy action for the testRemoveGroovyAction unit test
*/
@Action(
id = "testRemoveAction",
name = "Test Remove Action",
description = "Action for testing remove functionality",
actionExecutor = "groovy:testRemoveAction",
parameters = []
)
def execute() {
logger.info("Executing remove test action")
return EventService.NO_CHANGE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import org.apache.unomi.api.services.EventService
import org.apache.unomi.groovy.actions.annotations.Action
import org.apache.unomi.groovy.actions.annotations.Parameter

/**
* Test Groovy action for the testSaveGroovyAction unit test
*/
@Action(
id = "testSaveAction",
name = "Test Save Action",
description = "Action for testing save functionality",
actionExecutor = "groovy:testSaveAction",
parameters = []
)
def execute() {
logger.info("Executing test action")
return EventService.NO_CHANGE
}
Loading
Loading