2022-07-01

Setup local Keycloak for development

 




https://stackoverflow.com/a/72600716






Keycloak 18.0.2 doesn't required "/auth" as endpoint


new config:

keycloak.auth-server-url=http://localhost:8080

would be enough




We are sorry... page not found... error


Mandatory Config in Keycloak



while hitting we are sorry page not found error

was using http://localhost:8080/auth for keycloak.auth-server



while testing with https://www.keycloak.org/app/

hit error if didn't fill: https://www.keycloak.org/app/
to:

Root URL: https://www.keycloak.org/app/




If config below never in place, will trigger error: Invalid parameter: redirect_uri


Valid Redirect URIs: *








Respective Keycloak role in Spring Boot authRole config

 





keycloak.securityConstraints[0].authRoles[0]=xyz





Respective config in Keycloak (18.0.2)

In user Role mappings:





Different of SVNs

 SVN




Getting(install) SVN feature from
Eclipse Marketplace... VS  Install New Software






Eclipse Marketplace...





Install New Software

http://subclipse.tigris.org/update_1.6.x







subclipse.tigris.org no longer available...

 

http://subclipse.tigris.org/update_1.10.x
http://subclipse.tigris.org/update_1.6.x

above are not reachable...








Found a post telling to get from Eclipse Marketplace

Help > Eclipse Marketplace...





But during installation, but still retrieve resource from:












2022-06-10

"Spring" JPA "native query" java.lang.IndexOutOfBoundsException: Index: 1, Size: 1

 


"Spring" JPA "native query" java.lang.IndexOutOfBoundsException: Index: 1, Size: 1



Exception Snippet:

java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
at java.util.ArrayList.rangeCheck(ArrayList.java:659)
at java.util.ArrayList.get(ArrayList.java:435)
at org.springframework.data.repository.query.ResultProcessor$ProjectingConverter.toMap(ResultProcessor.java:278)
at org.springframework.data.repository.query.ResultProcessor$ProjectingConverter.getProjectionTarget(ResultProcessor.java:266)
at org.springframework.data.repository.query.ResultProcessor$ProjectingConverter.convert(ResultProcessor.java:253)
at org.springframework.data.repository.query.ResultProcessor$ChainingConverter$1.convert(ResultProcessor.java:201)
at org.springframework.data.repository.query.ResultProcessor$ChainingConverter.convert(ResultProcessor.java:212)
...

Throw error with:

List<Map<String, Object>> getNativeQueryList();

or

List<Tuple> getNativeQueryList();

Work around with:

List<Object[]> getNativeQueryList();






JUnit test - Caused by: javax.persistence.RollbackException: Transaction marked as rollbackOnly

 

Exception snippet:

12:02:34.849|WARN |Caught exception while allowing TestExecutionListener [org.springframework.test.context.transaction.TransactionalTestExecutionListener@1a84f40f] to process 'after' execution for test: method [public void test.com.tiongnam.repositories.TestInvoicePackageRepo.testListPossiblePackageWithInvoiceIdAndSummary()], instance [test.com.tiongnam.repositories.TestInvoicePackageRepo@ca2cd5e], exception [java.lang.IndexOutOfBoundsException: Index: 1, Size: 1]|main|org.springframework.test.context.TestContextManager
org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly
at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:526)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:761)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:730)
at org.springframework.test.context.transaction.TransactionContext.endTransaction(TransactionContext.java:128)
at org.springframework.test.context.transaction.TransactionalTestExecutionListener.afterTestMethod(TransactionalTestExecutionListener.java:227)
at org.springframework.test.context.TestContextManager.afterTestMethod(TestContextManager.java:319)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:94)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
...
Caused by: javax.persistence.RollbackException: Transaction marked as rollbackOnly
at org.hibernate.jpa.internal.TransactionImpl.commit(TransactionImpl.java:58)
at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:517)
... 26 common frames omitted





@Rollback(false)
MyJUnitTestClass


Calling a @Transactional Repo



change
@Rollback(true)






2022-05-31

Alternative - Error Code: 1093. You can't specify target table 'YOUR_TABLE' for update in FROM clause

 




Error Code: 1093. You can't specify target table 'YOUR_TABLE' for update in FROM clause



UPDATE YOUR_TABLE SET columnA = 'def' WHERE id IN (SELECT id AS MMID FROM YOUR_TABLE WHERE columnA = 'abc');



UPDATE YOUR_TABLE SET columnA = 'def' WHERE id IN ( SELECT MMID FROM ( SELECT id AS MMID FROM YOUR_TABLE WHERE columnA = 'abc' ) AS YOUR_ALIAS );



2022-04-20

JasperReport, always get blank PDF?

 
line below with new JREmptyDataSource() will get pdf as per expected.

jasperPrint = JasperFillManager.fillReport(report, jrParam, new JREmptyDataSource());



vs

where as using static _DATA_SOURCE_EMPTY, will always get blank pdf.

private static JREmptyDataSource _DATA_SOURCE_EMPTY = new JREmptyDataSource();

...
jasperPrint = JasperFillManager.fillReport(report, jrParam, _DATA_SOURCE_EMPTY);
...










2022-04-14

Multiple JasperPrint into a pdf with output as file and byte[]

 Multiple JasperPrint into a pdf with output as file and byte[]

JasperExportManager.exportReportToPdf vs JRPdfExporter.exportReport()








Found: https://community.jaspersoft.com/questions/526021/how-merge-multiple-pdf-jasper-reports-one







Multiple JasperPrint into a file
setCreatingBatchModeBookmarks

public void pdf() throws JRException { long start = System.currentTimeMillis(); List<JasperPrint> jasperPrintList = new ArrayList<JasperPrint>(); jasperPrintList.add((JasperPrint)JRLoader.loadObjectFromFile("build/reports/Report1.jrprint")); jasperPrintList.add((JasperPrint)JRLoader.loadObjectFromFile("build/reports/Report2.jrprint")); jasperPrintList.add((JasperPrint)JRLoader.loadObjectFromFile("build/reports/Report3.jrprint")); JRPdfExporter exporter = new JRPdfExporter(); exporter.setExporterInput(SimpleExporterInput.getInstance(jasperPrintList)); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput("build/reports/BatchExportReport.pdf")); SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration(); configuration.setCreatingBatchModeBookmarks(true); exporter.setConfiguration(configuration); exporter.exportReport(); System.err.println("PDF creation time : " + (System.currentTimeMillis() - start)); }



JRPdfExporter to byte array

Found: https://www.tabnine.com/code/java/methods/net.sf.jasperreports.engine.export.JRPdfExporter/setParameter

public byte[] exportToPdf(JasperPrint jasperPrint) throws JRException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); JRPdfExporter exporter = new JRPdfExporter(jasperReportsContext); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(baos)); exporter.exportReport(); return baos.toByteArray(); }




more Java JRPdfExporter.exportReport方法代碼示例
Found: https://vimsky.com/zh-tw/examples/detail/java-method-net.sf.jasperreports.engine.export.JRPdfExporter.exportReport.html


示例1: export
示例2: savePDFReportToOutputStream
示例3: concatPDFReport
示例4: concatPDFReportEncrypted


Billson: file
示例5: pdf























2022-04-13

Resolved: No qualifying bean of type 'org.springframework.boot.web.client.RestTemplateBuilder'

 
JUnit
TestCase
Spring Boot


Add annotation of 
@AutoConfigureWebClient
to your test case.

org.springframework.boot.test.autoconfigure.web.client.AutoConfigureWebClient



Together with
@ContextConfiguration(classes = {LocalConfig.class})

org.springframework.test.context.ContextConfiguration


public class LocalConfig {

/**
*/
public LocalConfig() {
}
@Bean
public RestTemplate restTemplate(RestTemplateBuilder builder) {
   // Do any additional configuration here
   return builder.build();
}

}


to resolve this.

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.boot.web.client.RestTemplateBuilder' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}






org.springframework.beans.factory.BeanFactory.getBean( ) with args

 


org.springframework.beans.factory.BeanFactory.getBean( ) with args


Source URL: https://www.programcreek.com/java-api-examples/?class=org.springframework.beans.factory.BeanFactory&method=getBean

public static void main(String[] args) {
    // 配置 XML 配置文件
    // 启动 Spring 应用上下文
    BeanFactory beanFactory = new ClassPathXmlApplicationContext("classpath:/META-INF/bean-instantiation-context.xml");
    User user = beanFactory.getBean("user-by-static-method", User.class);
    User userByInstanceMethod = beanFactory.getBean("user-by-instance-method", User.class);
    User userByFactoryBean = beanFactory.getBean("user-by-factory-bean", User.class);
    System.out.println(user);
    System.out.println(userByInstanceMethod);
    System.out.println(userByFactoryBean);

    System.out.println(user == userByInstanceMethod);
    System.out.println(user == userByFactoryBean);

}


Details at:







2022-04-12

@RunWith vs @SpringBootTest

 

https://stackoverflow.com/questions/58901288/springrunner-vs-springboottest







@RunWith(SpringRunner.class) : You need this annotation to just enable spring boot features like @Autowire@MockBean etc.. during junit testing

is used to provide a bridge between Spring Boot test features and JUnit. Whenever we are using any Spring Boot testing features in our JUnit tests, this annotation will be required.

@SpringBootTest : This annotation is used to load complete application context for end to end integration testing

The @SpringBootTest annotation can be used when we need to bootstrap the entire container. The annotation works by creating the ApplicationContext that will be utilized in our tests.

Here is the article with clear examples on both scenarios Baeldung














Resolved: Caused by: java.lang.IllegalStateException: Unable to retrieve @EnableAutoConfiguration base packages

 




Referring to URL below:
https://github.com/spring-projects/spring-boot/issues/10465#issuecomment-336397898
 
Added @AutoConfigurationPackage to avoid error: Caused by: java.lang.IllegalStateException: Unable to retrieve @EnableAutoConfiguration base packages

into the class u made as:
org.springframework.context.annotation.Configuration




Relevant reads:
  1. https://blog.csdn.net/wuqingsssss/article/details/113115809
  2. https://its401.com/article/wuqingsssss/113115809




2022-04-07

Regex to split htop details

 

^( *\d+) (\w+) +(\d+) +(-?\d+) +(\d+.?\d?\w?) +(\w+) +(\w+) +S +(\d+.?\d+) +(\d+.?\d+) +(\d+h?:?\d?\d?:?\.?\d?\d?) +[├│└][\+─ ] (.*)$


2022-04-05

Web characters - emoji

 



Emoji 14.02021-09-14Unicode 14.0E14.0



🌏🗺🧭
🦷
➀➁➂➃➄➅➆➇➈➉
🏀
🎮🕹🎮🕹
🔋

🉑


more at: https://www.w3schools.com/charsets/ref_utf_dingbats.asp




🇲🇾
more at: https://unicode.org/emoji/charts/full-emoji-list.html



Emoji Versions

Emoji VersionDateUnicode VersionData File Comment
N/AvariousvariousE0.0
N/A2010-10-11Unicode 6.0E0.6
N/A2014-06-16Unicode 7.0E0.7
Emoji 1.02015-06-09Unicode 8.0E1.0
Emoji 2.02015-11-12Unicode 8.0E2.0
Emoji 3.02016-06-03Unicode 9.0E3.0
Emoji 4.02016-11-22Unicode 9.0E4.0
Emoji 5.02017-06-20Unicode 10.0E5.0
Emoji 11.02018-05-21Unicode 11.0E11.0
Emoji 12.02019-03-05Unicode 12.0E12.0
Emoji 12.12019-10-21Unicode 12.1E12.1
Emoji 13.02020-03-10Unicode 13.0E13.0
Emoji 13.12020-09-15Unicode 13.0E13.1
Emoji 14.02021-09-14Unicode 14.0E14.0




7 PRINCIPLES OF DATA PROTECTION

 


https://www.pdp.gov.my/jpdpv2/public/principles-of-data-protection/?lang=en

PRINCIPLES OF DATA PROTECTION

Share

Share on facebook
Share on google
Share on twitter

7 PRINCIPLES OF DATA PROTECTION

Reasonably, people should know how we obtained personal data and recognizing the 7 Principles Personal Data Protection prescribed by the PDPA, 2010 (Act 709) ie:-

7 Personal Data Protection Principles which must be adhered to under section 5 (1) of the Act & nbsp; The 709-by maintaining the integrity of personal data :-

  • First – General Principles in which a consumer is not allowed to process personal data of someone else without permission. Understanding the process here should be understood as the control of data through automated means or methods or computing or any other process.
  • Second – must comply with the Principles of Notice and Choice in which information and destination prefix notified to data subjects concerned.
  • Third – Disclosure Principle destination is a subject of personal data in order to identify the purposes for which personal data are to be disclosed.
  • Fourth – Principles of Safety & ndash; when processing personal data any subject, taking steps to keep the data safe, non-modified, misused or given to the parties that do not concerned.
  • Fifth – Retention Principle: The personal data shall not be kept in any processing over the time limit required.
  • Sixth – Data Integrity Principle & ndash; any personal data ascertained so accurate, complete, not misleading and meets the intent of the latest data is stored and processed.
  • Seventh – Access Principle: a person shall be entitled to access personal data held by a data user and also can correct it in order to update its data.

Therefore Malaysians in particular should be aware of their rights according to the principles contained in the Act.







Google Referrals