How to create new package tool in moqui?

I am trying to create a new tool for other components. The tool is for initializing firebase. Here is the file structure.
image

but the problem is I am unable to import the package, I am getting this error:

startup failed: sparts_Notification_initialize_Firebase: 11: Unexpected input: 'import' @ line 11, column 17. import com.pythys.firebase.FirebaseClient ^ 1 error

here is the tool code:

package com.pythys.firebase

import com.google.auth.oauth2.GoogleCredentials
import com.google.firebase.FirebaseApp
import com.google.firebase.FirebaseOptions
import com.google.firebase.messaging.FirebaseMessaging
import com.google.firebase.messaging.Message
import com.google.firebase.messaging.Notification
import org.slf4j.Logger
import org.slf4j.LoggerFactory

import groovy.transform.CompileStatic

@CompileStatic
public class FirebaseClient {
    private static final Logger logger = LoggerFactory.getLogger(FirebaseClient.class)

    public FirebaseClient(String keyFile) {
        def credentials = GoogleCredentials.fromStream(new FileInputStream(keyFile))
        FirebaseOptions options = new FirebaseOptions.Builder()
                .setCredentials(credentials)
                .build()
        FirebaseApp.initializeApp(options)
    }
}

here is how I am trying to import:

    <service verb="initialize" noun="Firebase">
        <actions>
            <script><![CDATA[
                import com.pythys.firebase.FirebaseClient
                ..........

I am not sure If I am missing anything.

1 Like

I think your service component hasn’t defined this tool package as a dependency. Please check the build.gradle file.

1 Like

Also I’m curious what your plan for firebase is.

If you are planning on using it as a database (which is an interesting idea), then you could base this component on: GitHub - moqui/moqui-orientdb: Moqui Framework tool component for OrientDB, a datasource plugin for the Entity Facade which is another nosql database integration with Moqui

apply plugin: 'groovy'

repositories {
    mavenCentral()
    flatDir name: 'localLib', dirs: "${rootDir}/framework/lib"
}

dependencies {
    implementation 'com.google.firebase:firebase-admin:9.1.0'
    implementation project(':framework')
    testImplementation project(':framework').configurations.testImplementation.allDependencies
}

test {
    description 'Run all pythys-firebase tests'
    dependsOn cleanTest
    useJUnitPlatform()
    include '**/FirebaseTestSuite.class'

    systemProperty 'moqui.runtime', "${rootDir}/runtime"
    systemProperty 'moqui.conf', 'conf/MoquiDevConf.xml'
    systemProperty 'moqui.init.static', 'true'
    maxHeapSize = "512M"

    testLogging.showStandardStreams = true

    classpath += files(sourceSets.main.output.classesDirs)
    classpath = classpath.filter { it.exists() }

    beforeTest { descriptor ->
        logger.lifecycle("Running test: ${descriptor}")
    }
}

This is my build.gradle file, please let me know if Im missing anything, thank you

1 Like

Thank you for your reply. I am trying to use Firebase for push notifications.

1 Like