Thursday, May 5, 2022

ZOHO QUESTION : Given a 9×9 sudoku we have to evaluate it for its correctness.

Here we have some simplest way to check the sudoku validation. And we have few discussion and suggestion on this post comments section, so we decided to give the solution as per the discussion.

Coding snippet:

private static boolean check(){

    int[][] l_arrSudukoMatrix = new int[][] {
{ 5, 1, 3, 6, 8, 7, 2, 4, 9 },
{ 8, 4, 9, 5, 2, 1, 6, 3, 7 },
{ 2, 6, 7, 3, 4, 9, 5, 8, 1 },
{ 1, 5, 8, 4, 6, 3, 9, 7, 2 },
{ 9, 7, 4, 2, 1, 8, 3, 6, 5 },
{ 3, 2, 6, 7, 9, 5, 4, 1, 8 },
{ 7, 8, 2, 9, 3, 4, 1, 5, 6 },
{ 6, 3, 5, 1, 7, 2, 8, 9, 4 },
{ 4, 9, 1, 8, 5, 6, 7, 2, 3 } }; //valid

for(int i = 0 ; i < l_arrSudukoMatrix.length; i++){
int sumRow = 0;
int sumColumn = 0;
int col = 0;
for(int j = 0 ; j < l_arrSudukoMatrix.length; j++){
sumColumn += l_arrSudukoMatrix[i][j];
sumRow += l_arrSudukoMatrix[j][i];
col = j;
}
if(sumRow != 45 || sumColumn != 45){
System.out.println("invalid");
return false;
}
}
System.out.println("valid");
return true;
}


Output: valid

If you change input array to duplicate any value in row or column you will get output like this.

Input: 

int[][] l_arrSudukoMatrix = new int[][] {
{ 5, 1, 3, 6, 8, 7, 2, 4, 9 },
{ 8, 4, 9, 5, 2, 1, 6, 3, 7 },
{ 2, 6, 7, 3, 4, 9, 5, 8, 1 },
{ 1, 5, 8, 4, 6, 3, 9, 7, 2 },
{ 9, 7, 4, 2, 1, 8, 3, 6, 5 },
{ 3, 2, 6, 7, 9, 5, 4, 1, 0 }, //0 is not a valid one.
{ 7, 8, 2, 9, 3, 4, 1, 5, 6 },
{ 6, 3, 5, 1, 7, 2, 8, 9, 4 },
{ 4, 9, 1, 8, 5, 6, 7, 2, 3 } };

Ouput: Invalid


Thank you.

Wednesday, April 27, 2022

No 'Access-Control-Allow-Origin' header is present on the requested resource.

To fix this error,  I used to enable spring security I have added below class in my spring boot application.

Here my API is running in 8080 and angular in 4200

@Configuration
@EnableWebSecurity
public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {

@Override
protected void configure(HttpSecurity http) throws Exception {
http.cors().and().authorizeRequests().
antMatchers( "/**")
.permitAll()
.anyRequest()
.authenticated();
}
}
And my controller is like
@RestController
public class AuthenticationController {

@RequestMapping(method = RequestMethod.GET, value = "/login")
public String userValidation(){
return "valid user";
}
    @GetMapping(path = "/basicauth")
    public AuthenticationBean basicauth() {
     return new AuthenticationBean("You are authenticated");
    }

}
After this I got below error, 

Access to XMLHttpRequest at 'http://localhost:8080/basicauth' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

GET http://localhost:8080/basicauth net::ERR_FAILED 401

HttpErrorResponse {headers: HttpHeaders, status: 0, statusText: 'Unknown Error', url: 'http://localhost:8080/basicauth', ok: false, …}

  1. message"Http failure response for http://localhost:8080/basicauth: 0 Unknown Error"
  2. name"HttpErrorResponse"
  3. okfalse
  4. status0
  5. statusText"Unknown Error"
  6. url"http://localhost:8080/basicauth"
Resolve this error I added below code in my controller class.
@CrossOrigin(origins = "http://localhost:4200")
@RestController
public class AuthenticationController {
//your methods are here...!
}
After this change the same call give response like below,



Thank you!

NullInjectorError: No provider for HttpClient!

From my angular application I tried call rest API backend. So I tried to use HttpClient to make a get call to API. The application complied successfully, but UI page was not loaded with html element, I saw only empty page. In console I find below error, error is very clear, I missed to import HttpClientModule in my AppModule.ts file.

Error thrown code snippet below, 
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
],

NullInjectorError: No provider for HttpClient! 


After import HttpClientModule, the html page loaded perfectly.
import {HttpClientModule} from '@angular/common/http';

@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
HttpClientModule
],

Thank you.

Monday, April 25, 2022

Http failure response for http://localhost:8080/alluser: 0 Unknown Error","error":{"isTrusted":true}

For a mini project I used spring boot as API and angular as UI.  In Spring boot I have added spring-boot-starter-security for secured my application. And I added my implementation for add/update/view data. After that I started working with Angular front end with mock data. 

Then I started integration part of UI with API. The first call I made from UI to API to fetch the uses available in DB and display them in list. While calling from UI, backend did not allow the UI request, because we have security check in API. In API I added security username and password. 

spring.security.user.name=user
spring.security.user.password=user

So we need to added security config to resolve this issue. I will post the solution
in next post.


Here is full error stack trace:
 main.js:1 ERROR Error: Uncaught (in promise): s1: {"headers":{"normalizedNames":{},"lazyUpdate":null,"headers":{}},"status":0,"statusText":"Unknown Error","url":"http://localhost:8080/alluser","ok":false,"name":"HttpErrorResponse","message":"Http failure response for http://localhost:8080/alluser: 0 Unknown Error","error":{"isTrusted":true}}
    at _e (polyfills.js:1:160289)
    at _e (polyfills.js:1:159769)
    at polyfills.js:1:161152
    at X.invokeTask (polyfills.js:1:154522)
    at Object.onInvokeTask (main.js:1:255253)
    at X.invokeTask (polyfills.js:1:154442)
    at X.runTask (polyfills.js:1:149526)
    at te (polyfills.js:1:156890)
    at X.invokeTask [as invoke] (polyfills.js:1:155703)
    at ee (polyfills.js:1:169257)

Thank you.

the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is application/json

Hi,

Today I created mini project using spring boot and angular to maintain user data. While adding the user from angular I got below error. 

org.apache.tomcat.util.http.fileupload.impl.InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is application/json
at org.apache.tomcat.util.http.fileupload.impl.FileItemIteratorImpl.init(FileItemIteratorImpl.java:151) ~[tomcat-embed-core-9.0.60.jar:9.0.60]
at 

And code is like this.

@RequestMapping(value="adduser", method = RequestMethod.POST)
@ResponseBody
public User createNewUser(@RequestPart User user){
user.setCreatedDate(LocalDateTime.now());
return userService.createNewUser(user);
}

<form [formGroup]="userForm"  (ngSubmit)="onUserDetail()">
<div class="container">
Username: <input class="input_filed" type="text" name="username" formControlName="username">
Email: <input class="input_filed" type="text" name="email" formControlName="email">
Title: <input class="input_filed" type="text" name="title" formControlName="title">
<button >Add</button>
</div>
</form>
So clearly it says the format of input param of createNewUse() method was not expected.
I tried to add the @RequestPart("user") also I end up with same error.

Then I used @RequestBody instead of @RequestPart. This works for me I am able to send the
user data from UI to backend.

Working code:


@RequestMapping(value="adduser", method = RequestMethod.POST)
@ResponseBody
public User createNewUser(@RequestBody User user){
user.setCreatedDate(LocalDateTime.now());
return userService.createNewUser(user);
}

Thanks all. Full error stack trace is below.


org.apache.tomcat.util.http.fileupload.impl.InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is application/json
at org.apache.tomcat.util.http.fileupload.impl.FileItemIteratorImpl.init(FileItemIteratorImpl.java:151) ~[tomcat-embed-core-9.0.60.jar:9.0.60]
at 
 org.apache.tomcat.util.http.fileupload.impl.InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is application/json
at org.apache.tomcat.util.http.fileupload.impl.FileItemIteratorImpl.init(FileItemIteratorImpl.java:151) ~[tomcat-embed-core-9.0.60.jar:9.0.60]
at org.apache.tomcat.util.http.fileupload.impl.FileItemIteratorImpl.getMultiPartStream(FileItemIteratorImpl.java:205) ~[tomcat-embed-core-9.0.60.jar:9.0.60]
at org.apache.tomcat.util.http.fileupload.impl.FileItemIteratorImpl.findNextItem(FileItemIteratorImpl.java:224) ~[tomcat-embed-core-9.0.60.jar:9.0.60]
at org.apache.tomcat.util.http.fileupload.impl.FileItemIteratorImpl.<init>(FileItemIteratorImpl.java:142) ~[tomcat-embed-core-9.0.60.jar:9.0.60]
at org.apache.tomcat.util.http.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:252) ~[tomcat-embed-core-9.0.60.jar:9.0.60]
at org.apache.tomcat.util.http.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:276) ~[tomcat-embed-core-9.0.60.jar:9.0.60]
at org.apache.catalina.connector.Request.parseParts(Request.java:2932) ~[tomcat-embed-core-9.0.60.jar:9.0.60]
at org.apache.catalina.connector.Request.getParts(Request.java:2834) ~[tomcat-embed-core-9.0.60.jar:9.0.60]
at org.apache.catalina.connector.RequestFacade.getParts(RequestFacade.java:1098) ~[tomcat-embed-core-9.0.60.jar:9.0.60]
at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.parseRequest(StandardMultipartHttpServletRequest.java:95) ~[spring-web-5.3.18.jar:5.3.18]
at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.<init>(StandardMultipartHttpServletRequest.java:88) ~[spring-web-5.3.18.jar:5.3.18]
at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.<init>(StandardMultipartHttpServletRequest.java:72) ~[spring-web-5.3.18.jar:5.3.18]
at org.springframework.web.multipart.support.MultipartResolutionDelegate.asMultipartHttpServletRequest(MultipartResolutionDelegate.java:82) ~[spring-web-5.3.18.jar:5.3.18]
at org.springframework.web.multipart.support.RequestPartServletServerHttpRequest.<init>(RequestPartServletServerHttpRequest.java:68) ~[spring-web-5.3.18.jar:5.3.18]
at org.springframework.web.servlet.mvc.method.annotation.RequestPartMethodArgumentResolver.resolveArgument(RequestPartMethodArgumentResolver.java:139) ~[spring-webmvc-5.3.18.jar:5.3.18]
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:122) ~[spring-web-5.3.18.jar:5.3.18]
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:179) ~[spring-web-5.3.18.jar:5.3.18]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:146) ~[spring-web-5.3.18.jar:5.3.18]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117) ~[spring-webmvc-5.3.18.jar:5.3.18]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) ~[spring-webmvc-5.3.18.jar:5.3.18]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) ~[spring-webmvc-5.3.18.jar:5.3.18]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.3.18.jar:5.3.18]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1067) ~[spring-webmvc-5.3.18.jar:5.3.18]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963) ~[spring-webmvc-5.3.18.jar:5.3.18]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.3.18.jar:5.3.18]
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) ~[spring-webmvc-5.3.18.jar:5.3.18]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:681) ~[tomcat-embed-core-9.0.60.jar:4.0.FR]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.3.18.jar:5.3.18]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:764) ~[tomcat-embed-core-9.0.60.jar:4.0.FR]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227) ~[tomcat-embed-core-9.0.60.jar:9.0.60]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.60.jar:9.0.60]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.60.jar:9.0.60]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.60.jar:9.0.60]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.60.jar:9.0.60]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-5.3.18.jar:5.3.18]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.18.jar:5.3.18]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.60.jar:9.0.60]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.60.jar:9.0.60]
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-5.3.18.jar:5.3.18]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.18.jar:5.3.18]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.60.jar:9.0.60]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.60.jar:9.0.60]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-5.3.18.jar:5.3.18]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.18.jar:5.3.18]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.60.jar:9.0.60]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.60.jar:9.0.60]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197) ~[tomcat-embed-core-9.0.60.jar:9.0.60]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) [tomcat-embed-core-9.0.60.jar:9.0.60]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) [tomcat-embed-core-9.0.60.jar:9.0.60]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135) [tomcat-embed-core-9.0.60.jar:9.0.60]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.60.jar:9.0.60]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) [tomcat-embed-core-9.0.60.jar:9.0.60]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:360) [tomcat-embed-core-9.0.60.jar:9.0.60]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399) [tomcat-embed-core-9.0.60.jar:9.0.60]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-embed-core-9.0.60.jar:9.0.60]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:889) [tomcat-embed-core-9.0.60.jar:9.0.60]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1743) [tomcat-embed-core-9.0.60.jar:9.0.60]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.60.jar:9.0.60]
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) [tomcat-embed-core-9.0.60.jar:9.0.60]
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) [tomcat-embed-core-9.0.60.jar:9.0.60]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.60.jar:9.0.60]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_231]


Friday, April 22, 2022

Coding interview questions: Python

Hello, 

Here in this post I will solve some basic coding interview question. This time I used python. Yes its cool.

Find second largest number in given array?

input: [1,2,0,9,8] output: 8
input: [0,1,-1,-2] output: 0
input: [3] output: 
input: [] output: 
def findSecondLargestNumber(arr_list):
  largest = None
  secondL = None
  for i in arr_list:
    if largest == None:
      largest = i
    elif i > largest:
      secondL = largest
      largest = i
    elif secondL == None:
      secondL = i
    elif i > secondL:
      secondL = i
    
  print(secondL)

findSecondLargestNumber([0-11])

Find given two string inputs are reverse?
input: "ABC", "CBA" Output : True
input: "ABC", "cBA" Output : False
input: "ABC", "BCA" Ouput: False

def stringReverse(string1string2):
  for i in range(len(string1)):
    i1 = len(string2) - i -1;
    if(string1[i] != string2[i1]):
      return False
  return True 

stringReverse('ABC''cba')

Find given two string number, first input is greater than 2nd without using (int) convert?

Input: "1234" "4321" Ouput: False
Input: "1234" "321" Ouput: True
Input: "1234" "1234" Ouput: False

def largerthan(str1str2):
  if(len(str1) == len(str2)):
    for i in range(len(str1)):
      if str1[i] == str2[i]:
        continue
      elif str1[i] > str2[i]:
        return True
      else:
        return False
    return False
  elif len(str1) > len(str2):
    return True
  else:
    return False

largerthan('723''234')

Find rooks are safe in chessboard, if u don't know what is that? Don't worry, in chessboard rook can move vertical and horizontal line, if any rook block this we then moving rook will kill that?

For testing purpose I am using 4*4 board input instead of 8*8
Input: [[1,0,0,0],[0,1,0,0],[0,0,0,0],[0,0,0,1]] Output: True
Input: [[1,0,0,0],[0,1,0,0],[0,1,0,0],[0,0,0,1]] Output: False (because array[1,1] and array[2,1] are in same vertical line,
so the rooks are not safe)

def rookSafe(arr):
  for i in range(len(arr)):
    countRow = 0;
    countCol = 0;
    for j in range(len(arr)):
      countRow += arr[i][j]
      countCol += arr[j][i]
      if countCol > 1 or countRow > 1:
        return False
  return True

rookSafe([[1,0,0,0],[0,1,0,0],[0,0,0,0],[0,0,0,1]])


Java solution will be post soon!!👀

Thank you.

Thursday, April 21, 2022

Error: The Angular Compiler requires TypeScript 4.2.3 and 4.4.0 but 4.6.3 was found instead.

After resolve this error, ng serve brings up new error.


Error: The Angular Compiler requires TypeScript >=4.2.3 and <4.4.0 but 4.6.3 was found instead.


So again version mismatch, but this time error it self it clear so I easily fixed this error like pro.

Again I changed typescript version  from "typescript""^4.3.5" to "typescript""4.3.5".

changed What happen when we have while doing npm install angular finds most recent version of typescript, in package-lock.json "typescript""4.6.3" is got update. so I have change "typescript""4.3.5" in package.json.

This solved my issue. 


Conclusion: If you face any weird error from core/webpack or any check your typescript and angular version between package.json and package-lock.json so that we can find between what you expected to load to build and what angular try to find.

Error: Error on worker #1: TypeError: ts.isNamedTupleMember is not a function

While trying to run ng serve on my angular project I got below error,

- Generating browser application bundles (phase: setup)...Compiling @angular/core : es2015 as esm2015
Error: Error on worker #1: TypeError: ts.isNamedTupleMember is not a function
    at StaticInterpreter.visitType (C:\Workspace\SPRINGBOOT\untitled\node_modules\@angular\compiler-cli\src\ngtsc\partial_evaluator\src\interpreter.js:699:25)
    at StaticInterpreter.visitVariableDeclaration (C:\Workspace\SPRINGBOOT\untitled\node_modules\@angular\compiler-cli\src\ngtsc\partial_evaluator\src\interpreter.js:303:46)
    at StaticInterpreter.visitDeclaration (C:\Workspace\SPRINGBOOT\untitled\node_modules\@angular\compiler-cli\src\ngtsc\partial_evaluator\src\interpreter.js:264:29)
    at StaticInterpreter.visitAmbiguousDeclaration (C:\Workspace\SPRINGBOOT\untitled\node_modules\@angular\compiler-cli\src\ngtsc\partial_evaluator\src\interpreter.js:372:22)
    at StaticInterpreter.visitIdentifier (C:\Workspace\SPRINGBOOT\untitled\node_modules\@angular\compiler-cli\src\ngtsc\partial_evaluator\src\interpreter.js:242:31)
    at StaticInterpreter.visitExpression (C:\Workspace\SPRINGBOOT\untitled\node_modules\@angular\compiler-cli\src\ngtsc\partial_evaluator\src\interpreter.js:99:31)
    at StaticInterpreter.visitPropertyAccessExpression (C:\Workspace\SPRINGBOOT\untitled\node_modules\@angular\compiler-cli\src\ngtsc\partial_evaluator\src\interpreter.js:342
:28)
    at StaticInterpreter.visitExpression (C:\Workspace\SPRINGBOOT\untitled\node_modules\@angular\compiler-cli\src\ngtsc\partial_evaluator\src\interpreter.js:102:31)
    at StaticInterpreter.visitCallExpression (C:\Workspace\SPRINGBOOT\untitled\node_modules\@angular\compiler-cli\src\ngtsc\partial_evaluator\src\interpreter.js:431:28)
    at StaticInterpreter.visitExpression (C:\Workspace\SPRINGBOOT\untitled\node_modules\@angular\compiler-cli\src\ngtsc\partial_evaluator\src\interpreter.js:105:31)
    at ClusterMaster.onWorkerMessage (C:\Workspace\SPRINGBOOT\untitled\node_modules\@angular\compiler-cli\ngcc\src\execution\cluster\master.js:195:27)
    at C:\Workspace\SPRINGBOOT\untitled\node_modules\@angular\compiler-cli\ngcc\src\execution\cluster\master.js:55:95
    at ClusterMaster.<anonymous> (C:\Workspace\SPRINGBOOT\untitled\node_modules\@angular\compiler-cli\ngcc\src\execution\cluster\master.js:293:57)
    at step (C:\Workspace\SPRINGBOOT\untitled\node_modules\@angular\compiler-cli\node_modules\tslib\tslib.js:143:27)
    at Object.next (C:\Workspace\SPRINGBOOT\untitled\node_modules\@angular\compiler-cli\node_modules\tslib\tslib.js:124:57)
    at C:\Workspace\SPRINGBOOT\untitled\node_modules\@angular\compiler-cli\node_modules\tslib\tslib.js:117:75
    at new Promise (<anonymous>)
    at Object.__awaiter (C:\Workspace\SPRINGBOOT\untitled\node_modules\@angular\compiler-cli\node_modules\tslib\tslib.js:113:16)
    at EventEmitter.<anonymous> (C:\Workspace\SPRINGBOOT\untitled\node_modules\@angular\compiler-cli\ngcc\src\execution\cluster\master.js:287:32)
    at EventEmitter.emit (events.js:314:20)
C:\Workspace\SPRINGBOOT\untitled\node_modules\@ngtools\webpack\src\ngcc_processor.js:139
            throw new Error(errorMessage + `NGCC failed${errorMessage ? ', see above' : ''}.`);
            ^
Error: NGCC failed.
    at NgccProcessor.process (C:\Workspace\SPRINGBOOT\untitled\node_modules\@ngtools\webpack\src\ngcc_processor.js:139:19)
    at C:\Workspace\SPRINGBOOT\untitled\node_modules\@ngtools\webpack\src\ivy\plugin.js:129:27
    at Hook.eval [as call] (eval at create (C:\Workspace\SPRINGBOOT\untitled\node_modules\tapable\lib\HookCodeFactory.js:19:10), <anonymous>:26:1)
    at Hook.CALL_DELEGATE [as _call] (C:\Workspace\SPRINGBOOT\untitled\node_modules\tapable\lib\Hook.js:14:14)
    at Compiler.newCompilation (C:\Workspace\SPRINGBOOT\untitled\node_modules\webpack\lib\Compiler.js:1043:30)
    at C:\Workspace\SPRINGBOOT\untitled\node_modules\webpack\lib\Compiler.js:1088:29
    at Hook.eval [as callAsync] (eval at create (C:\Workspace\SPRINGBOOT\untitled\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:20:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (C:\Workspace\SPRINGBOOT\untitled\node_modules\tapable\lib\Hook.js:18:14)
    at Compiler.compile (C:\Workspace\SPRINGBOOT\untitled\node_modules\webpack\lib\Compiler.js:1083:28)
    at C:\Workspace\SPRINGBOOT\untitled\node_modules\webpack\lib\Watching.js:200:19
C:\Workspace\SPRINGBOOT\untitled>ng serve --fix
Unknown option: '--fix'


After spending lot of time on 'npm cache clean --fix' and deleting node_module, we have find that typescript version is creating problem here. So I upgrade my "typescript""3.6.5" to "typescript""^4.3.5"

This solved my issue. 

After that I run ng serve. There I got new error. 


Thank you!. 

Tuesday, April 19, 2022

java.lang.IllegalArgumentException: Not a managed type: class com.example.demo.entity.Customer

I tried to add couple of new entity classes in my project, service implementation and repository for those entity. Once after all done I tried to run my application, my IDE show up to below exception to me.


"org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customerRepo' defined in com.example.demo.repo.CustomerRepo defined in @EnableJpaRepositories declared on DemoApplication: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class com.example.demo.entity.Customer"

Here my Repo and Customer class

public interface CustomerRepo extends JpaRepository<Customer, Integer> {
}
public class Customer {
private Integer id;
private String name;
private String mobile;
private String email;
}

Its clearly says Customer class is not able to manage by JpaRepository. So JPA not able to consider this Customer class as entity. Because I used Customer class in Repo class as JpaRepository. 

Here the mistake is I forget to change the POJO to Entity. I missed to annotate Customer class with @Entity.


@Entity
@Table(name= "customer", schema = "public")
public class Customer {

So we need to add @Entity annotation to tell jpa this is a entity class to resolve 
this error.

This solve the above exception.

Machine learning key terms basics

ML - Key terms 

-> Classification - Identify a group/category from bunch of test data with given input data
-> To Classify a input we need to train a machine with algorithm with test data - training set
-> training set have N no of feature and one target variable
-> target variable is what we are trying to predict with ML algorithm.

-> In training set data target variable is known. 
-> Machine learn to find the relationship between feature and target variable - target variable is also known as class
-> To train a ML algorithm we need training data(X axis) and test data(Y axis)
-> To find desired level of accuracy is called knowledge representation
-> Regression is prediction of a numeric value
-> Classification and Regression is supervised learning

-> Non-supervised learning -> clustering - is a task where we group similar items
-> Non-supervised learning we will not have target value on data set.
-> Non-supervised learning reduce the data from many feature into smaller number of data, so we can visualize 2D or 3D format(eg: chart)
-> we need to find statical value that described data -> destiny estimation
-> training steps is not needed here because we will not have target value to train a machine.

-> Supervised learning - trying to predict the target value
-> if your target value is Yes/No or 1/2/3 or True/False this is called classification
-> if your target value is number of values like 0.00 to 100.00 or -9 to +9 is called regression 
-> Non-supervised learning - trying to find group for given data
    -> If you are trying to find group for given data is called clustering
-> If you need some numerical estimate to how strong the fit with each group , this is called Destiney estimation algorithm

-> To make better ML application we need to spend quality of time with data set. 

-> Steps of ML algorithm
-> create data
-> prepare input data
-> analyze input data
-> train the algorithm - Non-supervised does not required this steps
-> test algorithm
-> use it


-> Knn algorithm used to classify the data..  

continue in upcoming post...