Map<String,String> in JPA Entity

@Entity @Table(name="product") public class Product extends AbstractEntity {   @Id @GeneratedValue(strategy=GenerationType.AUTO) private Long id;   @ElementCollection(fetch = FetchType.EAGER) @JoinTable(name="product_attribute", joinColumns=@JoinColumn(name="product_id")) @MapKeyColumn(name="key") @Column(name="value") private Map<String, String> attributes = new HashMap<String, String>();   // …   }@Entity @Table(name="product") public class Product extends AbstractEntity { @Id @GeneratedValue(strategy=GenerationType.AUTO) private Long id; @ElementCollection(fetch = FetchType.EAGER) @JoinTable(name="product_attribute", joinColumns=@JoinColumn(name="product_id")) @MapKeyColumn(name="key") @Column(name="value") private Read more about Map<String,String> in JPA Entity[…]

Spring Data JPA: LIKE with OR query

@RepositoryRestResource public interface ProductRepository extends JpaRepository<Product, String> { List<Product> findByTitleContainingIgnoreCaseOrIdContainingIgnoreCase( @Param("q") String name, @Param("q") String id); }@RepositoryRestResource public interface ProductRepository extends JpaRepository<Product, String> { List<Product> findByTitleContainingIgnoreCaseOrIdContainingIgnoreCase( @Param("q") String name, @Param("q") String id); } Request path: GET https://localhost:8443/api/products/search/findByTitleContainingIgnoreCaseOrIdContainingIgnoreCase?q=…GET https://localhost:8443/api/products/search/findByTitleContainingIgnoreCaseOrIdContainingIgnoreCase?q=… If we need shorter request path: // GET https://localhost:8443/api/products/search/custom?q=… @RestResource(path = "custom") List<Product> findByTitleContainingIgnoreCaseOrIdContainingIgnoreCase( @Param("q") String name, Read more about Spring Data JPA: LIKE with OR query[…]

Scroll two divs simultaneously

On example of diff2html result let sides = this.diffResult.nativeElement.querySelectorAll(’.d2h-file-side-diff’); sides.forEach((sideDiv,idx) => { sideDiv.addEventListener(’scroll’, (event) => { let scrollLeft = event.target.scrollLeft; sides[idx==0?1:0].scrollLeft = scrollLeft; }); });let sides = this.diffResult.nativeElement.querySelectorAll(‘.d2h-file-side-diff’); sides.forEach((sideDiv,idx) => { sideDiv.addEventListener(‘scroll’, (event) => { let scrollLeft = event.target.scrollLeft; sides[idx==0?1:0].scrollLeft = scrollLeft; }); });

Active Directory/LDAP authentication with Spring Boot

package net.marioosh.ldapdemo;   import java.util.Arrays; import java.util.Collection;   import org.springframework.context.annotation.Configuration; import org.springframework.ldap.core.DirContextOperations; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.ldap.userdetails.LdapAuthoritiesPopulator;   @Configuration public class SecurityConfig extends WebSecurityConfigurerAdapter {   @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .anyRequest() .fullyAuthenticated() .and().formLogin(); }   @Override public void configure(AuthenticationManagerBuilder auth) throws Exception { Read more about Active Directory/LDAP authentication with Spring Boot[…]

XML – check is well formed

public boolean isValid(String xmlFilePath) throws FileNotFoundException { FileInputStream in = new FileInputStream(xmlFilePath); try { XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader staxXmlReader = factory.createXMLStreamReader(in); while(staxXmlReader.next() != XMLStreamConstants.END_DOCUMENT) {} return true; } catch (XMLStreamException e) { e.printStackTrace(); return false; } }public boolean isValid(String xmlFilePath) throws FileNotFoundException { FileInputStream in = new FileInputStream(xmlFilePath); try { XMLInputFactory factory = XMLInputFactory.newInstance(); Read more about XML – check is well formed[…]

*ngTemplateOutlet

<ng-template #toolbar> lorem ipsum… </ng-template>   <!– put my template here –> <ng-container *ngTemplateOutlet="toolbar"></ng-container>   <!– and here –> <ng-container *ngTemplateOutlet="toolbar"></ng-container>   <!– and here, too 😉 –> <ng-container *ngTemplateOutlet="toolbar"></ng-container><ng-template #toolbar> lorem ipsum… </ng-template> <!– put my template here –> <ng-container *ngTemplateOutlet="toolbar"></ng-container> <!– and here –> <ng-container *ngTemplateOutlet="toolbar"></ng-container> <!– and here, too 😉 –> <ng-container Read more about *ngTemplateOutlet[…]

array to map with reduce()

let months = [ {month: 1, data1: "test1", data2: "test2"}, {month: 2, data1: "test1", data2: "test2"}, {month: 3, data1: "test1", data2: "test2"} ];   let monthsAsMap = months.reduce((map, obj) => { map[obj.month] = obj; return map; }, {});   console.log(monthsAsMap); console.log(monthsAsMap[’2’]);let months = [ {month: 1, data1: "test1", data2: "test2"}, {month: 2, data1: "test1", data2: Read more about array to map with reduce()[…]

Simple AES-128 encryption in Java

import java.io.ByteArrayOutputStream;   import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec;   /** * AES-128 */ public class EncryptionUtils {   /** * initialisation vector */ private final static byte[] IV = "thai8bai9voo1haV".getBytes();   /** * algorithm/mode/padding */ private final static String TRANSFORMATION = "AES/CBC/PKCS5Padding";   /** * * @param text encrypted text * @param password need Read more about Simple AES-128 encryption in Java[…]