Skip to content

Commit

Permalink
🎨 MapStruct livetemplate wgme #242
Browse files Browse the repository at this point in the history
  • Loading branch information
trydofor committed May 24, 2024
1 parent af06e5a commit ed9d8b5
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 32 deletions.
2 changes: 1 addition & 1 deletion observe/docs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package pro.fessional.wings.slardar.security.impl;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
Expand All @@ -20,7 +19,6 @@
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder(toBuilder = true, builderMethodName = "")
public class DefaultWingsUserDetails implements WingsUserDetails {

private long userId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,8 @@ else if (d.getAuthType() == authType) {

// shallow copy with authType
if (dtl.getAuthType() == Null.Enm) {
dtl = dtl.toBuilder()
.authType(authType)
.build();
dtl = Details.$$.of(dtl);
dtl.setAuthType(authType);
}
else {
LocalDateTime now = Now.localDateTime();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package pro.fessional.wings.warlock.service.auth;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;
import org.mapstruct.factory.Mappers;
import pro.fessional.wings.faceless.convention.EmptySugar;
import pro.fessional.wings.slardar.context.TerminalContext;
import pro.fessional.wings.slardar.security.WingsAuthDetails;
Expand All @@ -27,7 +29,6 @@ public interface WarlockAuthnService {
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder(toBuilder = true, builderMethodName = "")
class Details {
// user
private long userId;
Expand All @@ -46,6 +47,28 @@ class Details {
public boolean isUninit() {
return EmptySugar.asEmptyValue(expiredDt);
}

/**
* auto generated by `wgme` live template
*/
@Mapper
public interface $$ {

void map(Details a, @MappingTarget Details b);

$$ INSTANCE = Mappers.getMapper($$.class);

@NotNull
static Details of(@Nullable Details source) {
final Details target = new Details();
INSTANCE.map(source, target);
return target;
}

static void to(@Nullable Details source, @NotNull Details target) {
INSTANCE.map(source, target);
}
}
}

enum Jane {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public interface AuthnDetailsMapper {
@Mapping(target = "authorities", ignore = true)
@Mapping(target = "accountNonLocked", ignore = true)
@Mapping(target = "accountNonExpired", ignore = true)
void mapping(WarlockAuthnService.Details source, @MappingTarget DefaultWingsUserDetails target);
void map(WarlockAuthnService.Details source, @MappingTarget DefaultWingsUserDetails target);

@Mapping(target = "status", ignore = true)
@Mapping(target = "expiredDt", ignore = true)
@InheritInverseConfiguration
void mapping(DefaultWingsUserDetails source, @MappingTarget WarlockAuthnService.Details target);
void map(DefaultWingsUserDetails source, @MappingTarget WarlockAuthnService.Details target);

AuthnDetailsMapper INSTANCE = Mappers.getMapper(AuthnDetailsMapper.class);

Expand All @@ -41,42 +41,43 @@ public interface AuthnDetailsMapper {
* @return new target
*/
@NotNull
static DefaultWingsUserDetails into(@Nullable WarlockAuthnService.Details source) {
static DefaultWingsUserDetails of(@Nullable WarlockAuthnService.Details source) {
final DefaultWingsUserDetails target = new DefaultWingsUserDetails();
INSTANCE.mapping(source, target);
INSTANCE.map(source, target);
return target;
}

/**
* build the target DefaultWingsUserDetails from the source Details
* create new DefaultWingsUserDetails from the source Details
*
* @param source the source from
* @param target the target into
* @return new target
*/
static void into(@Nullable WarlockAuthnService.Details source, @NotNull DefaultWingsUserDetails target) {
INSTANCE.mapping(source, target);
@NotNull
static WarlockAuthnService.Details of(@Nullable DefaultWingsUserDetails source) {
final WarlockAuthnService.Details target = new WarlockAuthnService.Details();
INSTANCE.map(source, target);
return target;
}

/**
* create new DefaultWingsUserDetails from the source Details
* build the target DefaultWingsUserDetails from the source Details
*
* @param source the source from
* @return new target
* @param target the target to
*/
@NotNull
static WarlockAuthnService.Details into(@Nullable DefaultWingsUserDetails source) {
final WarlockAuthnService.Details target = new WarlockAuthnService.Details();
INSTANCE.mapping(source, target);
return target;
static void to(@Nullable DefaultWingsUserDetails source, @NotNull WarlockAuthnService.Details target) {
INSTANCE.map(source, target);
}

/**
* build the target DefaultWingsUserDetails from the source Details
*
* @param source the source from
* @param target the target into
* @param target the target to
*/
static void into(@Nullable DefaultWingsUserDetails source, @NotNull WarlockAuthnService.Details target) {
INSTANCE.mapping(source, target);
static void to(@Nullable WarlockAuthnService.Details source, @NotNull DefaultWingsUserDetails target) {
INSTANCE.map(source, target);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public Details load(@NotNull Enum<?> authType, long userId) {
public void auth(DefaultWingsUserDetails userDetails, Details details) {
if (userDetails == null || details == null) return;

AuthnDetailsMapper.into(details, userDetails);
AuthnDetailsMapper.to(details, userDetails);

switch (details.getStatus()) {
case UNINIT, ACTIVE, INFIRM, UNSAFE -> {
Expand Down
14 changes: 10 additions & 4 deletions wings/wings-idea-live.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
<option name="JAVA_DECLARATION" value="true" />
</context>
</template>
<template name="wgmp" value="/**&#10; * auto generated by `wgmp` live template&#10; */&#10;@org.mapstruct.Mapper&#10;public interface $A2B$Mapper {&#10;&#10; $M$&#10; void mapping($A$ a, @org.mapstruct.MappingTarget $B$ b);&#10;&#10; @org.mapstruct.InheritInverseConfiguration&#10; void mapping($B$ a, @MappingTarget $A$ b);&#10;&#10; $A2B$Mapper INSTANCE = org.mapstruct.factory.Mappers.getMapper($A2B$Mapper.class);&#10; &#10; @org.jetbrains.annotations.NotNull&#10; static $B$ into(@org.jetbrains.annotations.Nullable $A$ source) {&#10; final $B$ target = new $B$();&#10; INSTANCE.mapping(source, target);&#10; return target;&#10; }&#10; &#10; static void into(@org.jetbrains.annotations.Nullable $A$ source, @org.jetbrains.annotations.NotNull $B$ target) {&#10; INSTANCE.mapping(source, target);&#10; }&#10;&#10; @org.jetbrains.annotations.NotNull&#10; static $A$ into(@org.jetbrains.annotations.Nullable $B$ source) {&#10; final $A$ target = new $A$();&#10; INSTANCE.mapping(source, target);&#10; return target;&#10; }&#10;&#10; static void into(@org.jetbrains.annotations.Nullable $B$ source, @org.jetbrains.annotations.NotNull $A$ target) {&#10; INSTANCE.mapping(source, target);&#10; }&#10;}" description="mapstruct Create &amp; Update" toReformat="true" toShortenFQNames="true">
<variable name="A" expression="" defaultValue="" alwaysStopAt="true" />
<template name="wgmp" value="/**&#10; * auto generated by `wgmp` live template&#10; */&#10;@org.mapstruct.Mapper&#10;public interface $A2B$ {&#10;&#10; $M$&#10; void map($A$ a, @org.mapstruct.MappingTarget $B$ b);&#10;&#10; @org.mapstruct.InheritInverseConfiguration&#10; void map($B$ a, @MappingTarget $A$ b);&#10;&#10; $A2B$ INSTANCE = org.mapstruct.factory.Mappers.getMapper($A2B$.class);&#10; &#10; @org.jetbrains.annotations.NotNull&#10; static $A$ of(@org.jetbrains.annotations.Nullable $B$ source) {&#10; final $A$ target = new $A$();&#10; INSTANCE.map(source, target);&#10; return target;&#10; }&#10;&#10; @org.jetbrains.annotations.NotNull&#10; static $B$ of(@org.jetbrains.annotations.Nullable $A$ source) {&#10; final $B$ target = new $B$();&#10; INSTANCE.map(source, target);&#10; return target;&#10; }&#10;&#10; static void to(@org.jetbrains.annotations.Nullable $B$ source, @org.jetbrains.annotations.NotNull $A$ target) {&#10; INSTANCE.map(source, target);&#10; }&#10;&#10; static void to(@org.jetbrains.annotations.Nullable $A$ source, @org.jetbrains.annotations.NotNull $B$ target) {&#10; INSTANCE.map(source, target);&#10; }&#10;}" description="AB mapstruct Create &amp; Update" toReformat="true" toShortenFQNames="true">
<variable name="A" expression="className()" defaultValue="" alwaysStopAt="true" />
<variable name="B" expression="" defaultValue="" alwaysStopAt="true" />
<variable name="M" expression="enum(&quot;&quot;,&quot;// https://mapstruct.org/documentation/stable/reference/html/&quot;,&quot;@org.mapstruct.Mapping(target = \&quot;setter\&quot;, expression = \&quot;java(source.method())\&quot;)&quot;,&quot;@org.mapstruct.Mapping(target = \&quot;setter\&quot;, source = \&quot;setter\&quot;)&quot;)" defaultValue="" alwaysStopAt="true" />
<variable name="A2B" expression="concat(regularExpression(A,&quot;&lt;.*&gt;|.*\\.&quot;,&quot;&quot;),&quot;To&quot;,regularExpression(B,&quot;&lt;.*&gt;|.*\\.&quot;,&quot;&quot;))" defaultValue="" alwaysStopAt="false" />
<variable name="A2B" expression="concat(regularExpression(A,&quot;&lt;.*&gt;|.*\\.&quot;,&quot;&quot;),&quot;$&quot;,regularExpression(B,&quot;&lt;.*&gt;|.*\\.&quot;,&quot;&quot;))" defaultValue="" alwaysStopAt="true" />
<variable name="M" expression="enum(&quot;&quot;,&quot;// https://mapstruct.org/docconcat(regularExpression(A,&quot;&lt;.*&gt;|.*\\.&quot;,&quot;&quot;),&quot;$&quot;,regularExpression(regularExpression(B,&quot;&lt;.*&gt;|.*\\.&quot;,&quot;&quot;),regularExpression(A,&quot;&lt;.*&gt;|.*\\.&quot;,&quot;&quot;),&quot;$&quot;))umentation/stable/reference/html/&quot;,&quot;@org.mapstruct.Mapping(target = \&quot;setter\&quot;, expression = \&quot;java(source.method())\&quot;)&quot;,&quot;@org.mapstruct.Mapping(target = \&quot;setter\&quot;, source = \&quot;setter\&quot;)&quot;)" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_DECLARATION" value="true" />
</context>
Expand Down Expand Up @@ -57,4 +57,10 @@
<option name="JAVA_STATEMENT" value="true" />
</context>
</template>
<template name="wgme" value="/**&#10; * auto generated by `wgme` live template&#10; */&#10;@org.mapstruct.Mapper&#10;public interface $$$$ {&#10; &#10; void map($A$ a, @org.mapstruct.MappingTarget $A$ b);&#10; &#10; $$$$ INSTANCE = org.mapstruct.factory.Mappers.getMapper($$$$.class);&#10; &#10; @org.jetbrains.annotations.NotNull&#10; static $A$ of(@org.jetbrains.annotations.Nullable $A$ source) {&#10; final $A$ target = new $A$();&#10; INSTANCE.map(source, target);&#10; return target;&#10; }&#10;&#10; static void to(@org.jetbrains.annotations.Nullable $A$ source, @org.jetbrains.annotations.NotNull $A$ target) {&#10; INSTANCE.map(source, target);&#10; }&#10;}" description="AA mapstruct Create &amp; Update" toReformat="true" toShortenFQNames="true">
<variable name="A" expression="className()" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_DECLARATION" value="true" />
</context>
</template>
</templateSet>

0 comments on commit ed9d8b5

Please sign in to comment.