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 1e12099
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,67 +16,124 @@
* @author trydofor
* @since 2021-02-23
*/
@Mapper
public interface AuthnDetailsMapper {

@Mapping(target = "preAuthed", ignore = true)
@Mapping(target = "enabled", ignore = true)
@Mapping(target = "credentialsNonExpired", ignore = true)
@Mapping(target = "authorities", ignore = true)
@Mapping(target = "accountNonLocked", ignore = true)
@Mapping(target = "accountNonExpired", ignore = true)
void mapping(WarlockAuthnService.Details source, @MappingTarget DefaultWingsUserDetails target);
/**
* auto generated by `wgme` live template
*/
@Mapper
interface Details$ {

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

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

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

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

/**
* create new DefaultWingsUserDetails from the source Details
* auto generated by `wgmp` live template
*
* @param source the source from
* @return new target
* @author trydofor
* @since 2021-02-23
*/
@NotNull
static WarlockAuthnService.Details into(@Nullable DefaultWingsUserDetails source) {
final WarlockAuthnService.Details target = new WarlockAuthnService.Details();
INSTANCE.mapping(source, target);
return target;
}
@Mapper
interface Details$User {

/**
* build the target DefaultWingsUserDetails from the source Details
*
* @param source the source from
* @param target the target into
*/
static void into(@Nullable DefaultWingsUserDetails source, @NotNull WarlockAuthnService.Details target) {
INSTANCE.mapping(source, target);
@Mapping(target = "preAuthed", ignore = true)
@Mapping(target = "enabled", ignore = true)
@Mapping(target = "credentialsNonExpired", ignore = true)
@Mapping(target = "authorities", ignore = true)
@Mapping(target = "accountNonLocked", ignore = true)
@Mapping(target = "accountNonExpired", ignore = true)
void map(WarlockAuthnService.Details source, @MappingTarget DefaultWingsUserDetails target);

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

void map(DefaultWingsUserDetails source, @MappingTarget DefaultWingsUserDetails target);

void map(WarlockAuthnService.Details source, @MappingTarget WarlockAuthnService.Details target);

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

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

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

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

/**
* build the target DefaultWingsUserDetails from the source Details
*
* @param source the source from
* @param target the target to
*/
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 to
*/
static void to(@Nullable WarlockAuthnService.Details 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 to
*/
static void to(@Nullable DefaultWingsUserDetails source, @NotNull DefaultWingsUserDetails target) {
INSTANCE.map(source, target);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import pro.fessional.wings.slardar.security.WingsAuthDetails;
import pro.fessional.wings.slardar.security.impl.DefaultWingsUserDetails;
import pro.fessional.wings.warlock.service.auth.WarlockAuthnService;
import pro.fessional.wings.warlock.service.auth.help.AuthnDetailsMapper;
import pro.fessional.wings.warlock.service.auth.help.AuthnDetailsMapper.Details$User;

import java.util.Collections;
import java.util.List;
Expand Down 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);
Details$User.to(details, userDetails);

switch (details.getStatus()) {
case UNINIT, ACTIVE, INFIRM, UNSAFE -> {
Expand Down
11 changes: 9 additions & 2 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">
<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="mapstruct Create &amp; Update of Pair" toReformat="true" toShortenFQNames="true">
<variable name="A" expression="" 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="false" />
<context>
<option name="JAVA_DECLARATION" value="true" />
</context>
Expand Down Expand Up @@ -57,4 +57,11 @@
<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 $AA$ {&#10; &#10; void map($A$ a, @org.mapstruct.MappingTarget $A$ b);&#10; &#10; $AA$ INSTANCE = org.mapstruct.factory.Mappers.getMapper($AA$.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="mapstruct Create &amp; Update of me" toReformat="true" toShortenFQNames="true">
<variable name="A" expression="" defaultValue="" alwaysStopAt="true" />
<variable name="AA" expression="concat(regularExpression(A,&quot;&lt;.*&gt;|.*\\.&quot;,&quot;&quot;),&quot;$&quot;)" defaultValue="" alwaysStopAt="false" />
<context>
<option name="JAVA_DECLARATION" value="true" />
</context>
</template>
</templateSet>

0 comments on commit 1e12099

Please sign in to comment.