Skip to content
This repository has been archived by the owner on Mar 31, 2022. It is now read-only.

Add Kotlin Support #19

Closed
tmusin opened this issue Jun 30, 2021 · 1 comment
Closed

Add Kotlin Support #19

tmusin opened this issue Jun 30, 2021 · 1 comment
Assignees
Milestone

Comments

@tmusin
Copy link

tmusin commented Jun 30, 2021

For Jmix Studio ticket https://youtrack.haulmont.com/issue/JST-1447

Enviroment:
Jmix version: 1.0.0
Jmix Studio plugin version: 1.0.NIGHTLY623-211
IntelliJ version: IDEA 2021.1.3 (Community Edition)

TC:

  1. Create new Jmix project -> choose Jmix version 1.0.0 -> choose single-module-application template -> finish
  2. Add id 'org.jetbrains.kotlin.jvm' version '1.4.32' to plugins in build.gradle.
  3. Replace User.java with User.kt
User.kt
package your.package.name

import io.jmix.core.metamodel.annotation.JmixEntity
import io.jmix.security.authentication.JmixUserDetails
import io.jmix.core.entity.annotation.JmixGeneratedValue
import java.util.UUID
import io.jmix.core.entity.annotation.SystemLevel
import org.springframework.security.core.GrantedAuthority
import io.jmix.core.metamodel.annotation.InstanceName
import io.jmix.core.metamodel.annotation.DependsOnProperties
import javax.persistence.*
import javax.validation.constraints.Email

@JmixEntity
@Entity
@Table(name = "USER_", indexes = [Index(name = "IDX_USER__ON_USERNAME", columnList = "USERNAME", unique = true)])
class User : JmixUserDetails {
    @Id
    @Column(name = "ID")
    @JmixGeneratedValue
    var id: UUID? = null

    @Version
    @Column(name = "VERSION", nullable = false)
    var version: Int? = null

    @Column(name = "USERNAME", nullable = false)
    protected var username_: String? = null

    @SystemLevel
    @Column(name = "PASSWORD")
    protected var password_: String? = null

    @Column(name = "FIRST_NAME")
    var firstName: String? = null

    @Column(name = "LAST_NAME")
    var lastName: String? = null

    @Column(name = "EMAIL")
    var email: @Email String? = null

    @Column(name = "ACTIVE")
    var active: Boolean? = true

    @Transient
    protected var userAuthorities: Collection<GrantedAuthority?>? = null

    override fun getPassword(): String {
        return password_!!
    }

    override fun getUsername(): String {
        return username_!!
    }

    fun setUsername(username: String?) {
        this.username_ = username
    }

    fun setPassword(password: String?) {
        this.password_ = password
    }

    override fun getAuthorities(): Collection<GrantedAuthority?> {
        return if (userAuthorities != null) userAuthorities!! else emptyList()
    }

    override fun setAuthorities(authorities: Collection<GrantedAuthority?>) {
        this.userAuthorities = authorities
    }

    override fun isAccountNonExpired(): Boolean {
        return true
    }

    override fun isAccountNonLocked(): Boolean {
        return true
    }

    override fun isCredentialsNonExpired(): Boolean {
        return true
    }

    override fun isEnabled(): Boolean = active == true

    @get:DependsOnProperties("firstName", "lastName", "username_")
    @get:InstanceName
    val displayName: String
        get() = String.format(
            "%s %s [%s]", if (firstName != null) firstName else "",
            if (lastName != null) lastName else "", username_
        ).trim { it <= ' ' }
}
  1. Run App

AR
Execution failed for task ':bootRun'.
Caused by: java.lang.IllegalArgumentException: MetaClass not found for class your.package.name.User.

After making the fixes, make sure that the problem does not return in a project without Java sources, and that the enhancing is running on 100% Kotlin projects.

It is also possible to encounter the error:
Entity class your.package.name.User is missing some of enhancing interfaces: PersistenceObject, PersistenceWeaved, PersistenceWeavedFetchGroups.

@tmusin tmusin added the type: bug Something isn't working label Jun 30, 2021
@tmusin tmusin added this to the 1.1.0 milestone Jun 30, 2021
@Gasloff Gasloff assigned Gasloff and andreysubbotin and unassigned Gasloff Jun 30, 2021
@tmusin
Copy link
Author

tmusin commented Jun 30, 2021

Suggested changes in branch feature/JST-1447

andreysubbotin pushed a commit that referenced this issue Jul 6, 2021
andreysubbotin added a commit that referenced this issue Jul 6, 2021
@knstvk knstvk added this to Release 1.1 (October 2021) in Jmix Roadmap - OUTDATED Aug 10, 2021
@knstvk knstvk removed the type: bug Something isn't working label Aug 10, 2021
@knstvk knstvk removed this from October 2021 feature release 1.1 in Jmix Roadmap - OUTDATED Mar 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants