Wednesday, 15 November 2017

git Repo

A year before had chat with my Guru/ Friend / Senior/ TL Bala.
He said lot about GIT. would like to do experiments on it.
Now got a chance on it.

went for an interview, they asked to do crud operations and upload it in GitHub.
cannot able to do that on the same day, however, next day, started that process.

so this what i did, 

1. generate ssh key from eclipse.
2. add that ssh key in Github.
3. commit and publish the code.

seems easy right. Yah, it is easy in eclipse. Eclipse made the process simple. I will explain what is happening behind in the part 2.

and that repo https://github.com/hunkr11/intellect i shared with Balaji, my senior in saksoft.
Asked him to fork it.
to my knowledge, forking is like importing my repository in github to his repository, and can make changes in that repository. It won't affect mine.

then ask him to raise a pull request.
well, pull request is after forking and made some changes, then the forked person would like to add their changes to the main copy.
in this scenario, balaji made some changes, he raised a pull request, then i received that intimation. i reviewed balaji's code then merged it.



so, that experiment is successful.


Next, day i want to try the same for angular code using Visual studio Code.

likewise created the repo.
tried to commit the code, show the error unknown user.
after googling, found need to set the user name and email for github to commit

$ git config --global user.name hunkr11

$ git config --global user.name hunkr11@gmail.com
 then is error resolved.

then tried commiting again, the RSA error comes.
after googling understood the flow,

1. need to generated a ssh key(public key) for my github email id.

 ssh-keygen -t rsa -C "hunkr11@gmail.com

2. Add the generated ssh key to git

 ssh-add  (path)/(keyname)

3. add this key to Git as new SSH key

4. configure the user globally

 git config --global credential.helper wincred

that's it. now we can push our code to git using Visual Studio Code.

git remote add origin https://github.com/hunkr11/GIT.git
git push -u origin master

my angular repo: 
https://github.com/hunkr11/angular-shopping-cart

Tuesday, 24 October 2017

tHanKs Mohan !!!

always got struck with a querys.. 
Mohan, SQL Geek always helps me in fixing it..

this page is dedicated to him..

Tuesday, 24 Oct 2017


1. didn't thought of adding multiple parameter as comma separated in query. he did it in seconds.
 SELECT WORKER_ID,WORKER_NM FROM SHIFT_DET WHERE (SHIFT_ID , ROLE_CD ) IN  (
SELECT SHIFT_ID , ROLE_CD FROM SHIFT_DET WHERE SHIFT_DET_ID = 7451 )  

Wednesday, 25 Oct 2017

2. Query Optimization
Asked sql geek to look into the same query little bit modified by me.

SELECT WORKER_ID,
       WORKER_NM,
       STEV_SHIFT_DET_ID,
       SHIFT_SRC_DET_ID,
       stev_shift_id
  FROM (SELECT WORKER_ID,
               WORKER_NM,
               STEV_SHIFT_DET_ID,
               SHIFT_SRC_DET_ID,
               stev_shift_id
          FROM JPSNS.SNS_STEV_SHIFT_DET
         WHERE     (STEV_SHIFT_ID, ROLE_CD) IN
                      (SELECT STEV_SHIFT_ID, ROLE_CD
                         FROM JPSNS.SNS_STEV_SHIFT_DET
                        WHERE STEV_SHIFT_DET_ID = 7203)
               AND STEV_SHIFT_DET_ID <> 7203) A
 WHERE STEV_SHIFT_DET_ID NOT IN (SELECT NVL (SHIFT_SRC_DET_ID, 0)
                                   FROM JPSNS.SNS_STEV_SHIFT_DET

                                  WHERE stev_shift_id = A.stev_shift_id)

he altered the query like this,

SELECT WORKER_ID,
               WORKER_NM,
               STEV_SHIFT_DET_ID,
               SHIFT_SRC_DET_ID,
               stev_shift_id
          FROM JPSNS.SNS_STEV_SHIFT_DET d
         WHERE     (STEV_SHIFT_ID, ROLE_CD) IN
                      (SELECT STEV_SHIFT_ID, ROLE_CD
                         FROM JPSNS.SNS_STEV_SHIFT_DET
                        WHERE STEV_SHIFT_DET_ID = 7203)
               AND STEV_SHIFT_DET_ID <> 7203
 and not exists (SELECT 'X' FROM JPSNS.SNS_STEV_SHIFT_DET d1
                                  WHERE stev_shift_id = d.stev_shift_id and
                                  d.STEV_SHIFT_DET_ID = d1.SHIFT_SRC_DET_ID

                                  );

also he looked into cost of both the queries using CTRL + E in toad.


and gave me pretty good suggestions, like 
TABLE ACCESS SHOULD NOT COME FULL for that need to set index for the shift id.
also said, using of NOT IN is elementary practice, better to use NOT EXIST.

Thursday, 30 March 2017

Filter request url based on func code - 1111 Spring security

hope, from the title itself, you would have guess, yes URL restriction based on JAS  response. 


i'm not sure you guys can follow the above link easily, however, in my case, i can. i say you why, i have implemented a functionality of disabling a button in JSP page.


so, it looks like the continuation of that, thought will complete in some time. but it says, not so easy buddy. 😄

Case i)
earlier, i had the object in the session and i can get object as ${OBJECT} and give permission. 


<sec:accesscontrollist hasPermission="101001"   domainObject="${USER_FUNCTIONS}"> 
Now it is opposite, need to do the same implementation in JAVA used @PreAuthorize("hasPermission(OBJECT,'TEST123')"),  thought it would work. But it didn't.

got blocked in here..

current scenario, 
* having the object in the session, nee to get that object and make the @PreAuthorize to work. but, how i ll set the session object in the annotation.

i tried getting the session object gloabally using, 

HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder
.currentRequestAttributes()).getRequest();
HttpSession session = request.getSession();
List<String> functionList = (List<String>)session.getAttribute("OBJECT");

since in spring, the controller will compile in the run time itself, i got error. 

case ii)

since the case i) didn't worked, another !dea spared.
doing the restriction in the configuration itself, using

<intercept-url pattern="/test/edit/**" access="hasPermission(OBJECT,'TEST123')"/>

this also didn't worked.

Finding a way to fix it.

Finally, after a long waiting fixed it

https://stackoverflow.com/a/45354372/2573744

Friday, 17 February 2017

i18N report xls

i18N report.. obviously the name say the meaning.. but the task is simple, the header in the report will be in english, but that should come from database.

* Initially thought of hitting db and taking a query and have 3 classes, 1 with list<reportvalue>, reportHeaderObject putting this object into another object say ReportObj. This !dea suggested by my Tech Lead, thanks. very good suggestion. while implementing another !dea hit in mind.

* Instead of creating new classes, set the value directly into the model, when we creating a variable. Think, you didn't got my point. let me clarify..

we have a cron/scheduler which will run every 15/30 mins, hit the database and update the properties file, that file we are using for i18N translation. My !dea is, instead of hitting to the db again, take the value directly from this properties file. googled..




ResourceBundle rb = ResourceBundle.getBundle("test.bundletest.mybundle");
String value = rb.getString(key);
with this, half of my task was over.. 

the second half is, how to set this object in the UI ?

saw the code, implemented by my colleague(obviously, on leave, enjoying weekend). Njoy Ramesh :D

PURE JAVASCRIPT (O _ O), however understandble.. 

changed in some places, get my object, set that as column header, BiNgOoo



Wednesday, 8 February 2017

thanks BaLaJ!

Today, Unknowingly deleted a column values, by noon, a colleague send mail to all, not to delete any values, without his knowledge like that




issue, got serious.. 

luckily found a query in http://stackoverflow.com/questions/19853150/rollback-a-committed-transaction
and thinking of how to implement it..
Explained the scenario to Balaji, with in minutes he put the query. Thats why, we call him Geekbot :D

ill say what i understand..

i took this oracle query..

select * from table as of timestamp timestamp '2017-02-08 17:30:00' order by id

1. Balaji, looked at it..
2. He copied, all the data,
3. pasted it in excel
4. kept only necessary columns
5. in excel he wrote query
 =CONCATENATE("UPDATE table SET TYPE='",C1,"' WHERE ID=",A1,";")
6. he press enter, update query came for all the entries..

Done. Big issue resolved in minutes, Thanks Geekbot. :D



Monday, 9 January 2017

Code Hints

// USING THIS LOGIC IN KEY UP TRIGGING A FUNCTION

ref : http://stackoverflow.com/questions/20281546/how-to-prevent-calling-of-en-event-handler-twice-on-fast-clicks

// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.

function debounce(func, wait, immediate) {
    var timeout;
    return function() {
        var context = this, args = arguments;
        var later = function() {
            timeout = null;
            if (!immediate) func.apply(context, args);
        };
        var callNow = immediate && !timeout;
        clearTimeout(timeout);
        timeout = setTimeout(later, wait);
        if (callNow) func.apply(context, args);
    };
};

Saturday, 12 November 2016

Angular 2


Saturday, 12 November 2016

Finally, Started learning angular 2.. It is been  a while, i wanted to learn angular 2 but got busy with other works.. Then my company itself provided us angular training + FOOD :D... hooo..! Thank You..
Training ended good.. hope i can share my road block in the following post.. :)

as of now.. https://angular.io/ & my angular trainer gitub
https://github.com/MicroTamil-Haribabu/ 



Thursdau 09 Feb 2017


Yep, After a long gap, i thought of start working on Angular 2. Now only got bit free from  project works.
so, now my 1st task to myself is, guess.. the same login page, what else it would be.. the developers who start learning a language obviously first task would be LOGIN page. So folks, lets begin.

I'm gonna continue with the application which i have in hand, which Mr.Haribabu helped me to create in a 3 days angular training.




Hope, it looks not that bad, lets do the logic in the fore-coming days.. ;)

Thursday, 20 October 2016

Spring Security + ACL button level Authentication + URL Authentication


In my case, i have some ArrayList of String in httpsession. i need to show a button the user, only if the button function name is available in that list. i have implement it via Spring Security ACL.
For that add ACL + spring security core jar in the classpath.
<dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-core</artifactId>
        <version>${spring.security.version}</version>
    </dependency>       
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>${spring.security.version}</version>
    </dependency>       
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-acl</artifactId>
        <version>${spring.security.version}</version>
    </dependency>
then, i have added the bean in xml.
<global-method-security pre-post-annotations="enabled">
  <expression-handler ref="expressionHandler"/>
</global-method-security>    
<beans:bean id="expressionHandler" class="org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler">
    <beans:property name="permissionEvaluator" ref="permissionEvaluator"/>
</beans:bean> 
<beans:bean id="permissionEvaluator" class="com.config.BasePermissionEvaluator"/>
then the handler class BasePermissionEvaluator, this class will evaluate, if that button has permission,
public class BasePermissionEvaluator implements PermissionEvaluator{
 @Override
 public boolean hasPermission(Authentication authentication, Object targetDomainObject, Object permission) {

  boolean hasPermission = true;
  // targetDomainObject [101001, 102001, 103001, 201001, 202001, 203001, 204001, 205001, 206001, 301001, 302001, 303001]permission : 303001
    @SuppressWarnings("unchecked")
    List<String> functionList =(List<String>) targetDomainObject;       
    if(!functionList.contains(permission.toString())) {
        hasPermission = false;  
    }
  return hasPermission;
 }

 @Override
 public boolean hasPermission(Authentication authentication,
   Serializable targetId, String targetType, Object permission) {
    throw new RuntimeException("Id and Class permissions are not supperted by this application");
 }
}
Finally in the jsp,
    <%@taglib uri="http://www.springframework.org/security/tags"
 prefix="sec"%>

<sec:accesscontrollist hasPermission="101001"   domainObject="${USER_FUNCTIONS}"> 
                    <button type="reset" id ="clearMPId"><spring:message code="mp.clear"/></button>
  </sec:accesscontrollist>   

for URL authentication, please follow

https://stackoverflow.com/a/45354372/2573744

Hope it helps.

Friday, 14 October 2016

Thursday, 1 September 2016

multi file upload + ajax post + jQuery

mannnnNNNNNN... File uploading.. File handling.. File writing.. File reading.. 
All these file operations, i'm bit scared of.. on these, i can now do file reading and file writing also can handle file.. but, this file upload.. i'm always had a fear of.. this time i got a chance to face it.. and lets see.. im confident, ill come up with a solution as always.. background songs going on.. lets start..

so.. this time, i got a partner.. to give me an UI.. so he gave me.. 

https://blueimp.github.io/jQuery-File-Upload/index.html

started with this.. implemented it my project.. UI came.. surprisingly, the expected functionality came.. however, as always, it ll not go that smooth.. i clicked the start button.. i cant guess.. where the url linq going.. ???

getting  an error SyntaxError: Unexpected token < in JSON at position 0

spend hours.. cannot find.. ask him to find, when uploading where the file is uploading.. 

http://hmkcode.com/spring-mvc-jquery-file-upload-multiple-dragdrop-progress/



Wednesday, 24 August 2016

JAS

JAS - Java Authentication Server

This time i been assigned with such  a wonderful task.. JASzzzzzzz
Initially, i given the requirement of authenticating username & password in the server and returning user functionalities, and according to that show the menu items..

With that i start the work.. 

SERVER Side 

i created a new dynamic project in eclipse.. Dynamic web module 2.5.. caz, AXIS 2 support only for this.. 
convert it a maven project..
-- include the AXIS 2 dependencies.. // not required

set the Axis 2 runtime location in  windows - preference - webservices - Axis 2.x Preference - "D:\Siva\AXIS2 "
Saying about AXIS 2, 
   - it is used to convert my class file to WSDL file
   - expose my class as a webservice.
yes most of my work done by itself.. thanks for all AXIS 2

so, i was saying.. create a interface and implement it in a class  in your package and do your business logic

Right click interface file which need to be expose - web services - create web service-  set the server environment and set the webservice environment as AXIS 2 - click finish.

Thats it.. you application is now deployed.. You have created soap server application.
to check it is working fine.. check your WSDL file is generating in the server.

Save the WSDL file. From this WSDL file we gonna generate the java file

Client Side

create a dynamic web project - convert it a maven project - in pom.xml add cxf dependency 

Saying abt CXF, it helps us to generate the java file from WSDL file we have.

<properties>
<cxf.version>3.1.0</cxf.version>
</properties>

<dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>${cxf.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>${cxf.version}</version>
        </dependency>

<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>

</dependency>

add the plugin

<!-- Generate Java classes from WSDL during build -->
            <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <version>${cxf.version}</version>
                <executions>
                    <execution>
                        <id>generate-sources</id>
                        <phase>generate-sources</phase>
                        <configuration>
                            <!-- which source folder the generated classes should be placed in a package -->
<!--                             <sourceRoot>${project.basedir}/src/main/java</sourceRoot> -->
                      <sourceRoot>${project.build.directory}/generated-sources/cxf</sourceRoot>
                            <wsdlOptions>
                                <wsdlOption>
                                    <!-- put the wsdl file in this location -->
                                    <wsdl>${project.basedir}/src/main/resources/wsdl/Login.wsdl</wsdl>
                                    <extraargs>
                                        <extraarg>-client</extraarg>
                                    </extraargs>
                                </wsdlOption>
                            </wsdlOptions>
                        </configuration>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                    </execution>
                </executions>

            </plugin>

 this ll generate the java file in the target folder.

from the generated end points, use that code to connect to the server. 

change the wsdl location,
 wsdlLocation = "http://localhost:9001/demo-server/services/DemoClass?wsdl",

Thats it. 

thats what i thought..

But.. 

It ll not finish that easy.. after reviewing i understand, the client requirement, they need the older version of axis.. ie.. AXIS 1.4 

AXIS 1.4 

Server side

hooooo.. got chance to do R&D on that..

same way i started.. of implementing it with AXIS 1.4

Road blocks:

  - In the server side, i cannot expose the webservice as before. it give me..

IWAB0398E Error in generating WSDL from Java:  java.lang.ClassCastException: org.apache.axis.encoding.ser.BeanSerializer cannot be cast to org.apache.axis.encoding.Serializer

  - Without the server running, i cannot generate the java files in the client side. caz, there is no end point.. 

so im struck here.. 

then got an idea of do everything manually, caz, at the starting of the internet, they did like that.. 
there was not ANT, Maven or Gradle.. 

so started.. with the reference 

http://www.digizol.com/2008/07/web-service-axis-tutorial-client-server.html

1. i compiled all the java files in commad promet | terminal.. 

javac -d classes test\com\admin\service\*.java 

2. generate wsdl file from the compiled classes

java org.apache.axis.wsdl.Java2WSDL  -o wsdl/Login.wsdl -n http://service.admin.com.test/  -l http://localhost:8080/admin/services/Login?wsdl=Login.wsdl test.com.admin.service.Login

3. Then created the deployment war file manually and deployed it in the server.

4. Finally linq the WSDL to the server

java org.apache.axis.client.AdminClient src\test\com\admin\service\generated\deploy.wsdd

now got struck here.. it is showing connection timeout.. means, it cannot find that deployed environment.. finding way to resolve it..

thanks to this site..
https://cuppajavamattiz.wordpress.com/2013/10/04/creating-a-simple-web-service-using-apache-axis-1-4/

caz of this i can able to continue with, what i was doing.. also gave me a bit confidence of, i going in the right path..

so 4th step gave me an error.. 
so this site was saying, to comment the following line in web.xml

<!--
 <servlet-mapping>
   <servlet-name>AdminServlet</servlet-name>
   <url-pattern>/servlet/AdminServlet</url-pattern>
 </servlet-mapping>
-->
did that. and did the 4th step again.. this time the error changed to
D:\WSDL2JAVA>java org.apache.axis.client.AdminClient src\sg\com\jp\admin\service \generated\deploy.wsdd Processing file src\sg\com\jp\admin\service\generated\deploy.wsdd Exception: AxisFault faultCode: {http://xml.apache.org/axis/}HTTP faultSubcode: faultString: (404)Not Found faultActor: faultNode: faultDetail: {}:return code: 404 &lt;html&gt;&lt;head&gt;&lt;title&gt;Apache Tomcat/7.0.67 - Error report&lt;/tit le&gt;&lt;style&gt;&lt;!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;ba ckground-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif; color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Ari al,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-f amily:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-famil y:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family: Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--&gt;&lt;/style&gt; &lt;/hea d&gt;&lt;body&gt;&lt;h1&gt;HTTP Status 404 - /axis/services/AdminService&lt;/h1& gt;&lt;HR size=&quot;1&quot; noshade=&quot;noshade&quot;&gt;&lt;p&gt;&lt;b&gt;ty pe&lt;/b&gt; Status report&lt;/p&gt;&lt;p&gt;&lt;b&gt;message&lt;/b&gt; &lt;u&gt ;/axis/services/AdminService&lt;/u&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;description&lt ;/b&gt; &lt;u&gt;The requested resource is not available.&lt;/u&gt;&lt;/p&gt;&lt ;HR size=&quot;1&quot; noshade=&quot;noshade&quot;&gt;&lt;h3&gt;Apache Tomcat/7. 0.67&lt;/h3&gt;&lt;/body&gt;&lt;/html&gt; {http://xml.apache.org/axis/}HttpErrorCode:404

i changed the project name to axis, created folder services, put my compiled class file in adminservice folder then i did the 4th step again, this time...

D:\WSDL2JAVA>java org.apache.axis.client.AdminClient src\test\com\admin\service \generated\deploy.wsdd Processing file src\test\com\admin\service\generated\deploy.wsdd <Admin>Done processing</Admin>

Yaaayyyyyyyyy... i have successfully exposed my web service.. also i can see my wdsl

So the Server part is completed, since we already had generated the java file from WSDL, i believe, we can directly connect to the end points through that. So the task moved to done.