Thursday, December 23, 2021

Spring Boot File Download Example

 From  below  documentations  have  good  articles  about   file  download .

 

 

  • https://javadeveloperzone.com/spring-boot/spring-boot-download-file-example/


  • Basically there is no need to add produces = "application/pdf" in RequestMapping as it seems to try to convert the ResponeBody internally. You can just add MediaType to response headers which is what you need.
@ResponseBody
@RequestMapping(value = "get/pdf/{id}", headers="Accept=*/*", method = RequestMethod.GET)
public ResponseEntity<InputStreamResource> getPdfContractById(@PathVariable("id") Long id){
        // Get the remove file based on the fileaddress
        RemoteFile remotefile = new RemoteFile(id);

        // Set the input stream
        InputStream inputstream = remotefile.getInputStream();
        // asume that it was a PDF file
        HttpHeaders responseHeaders = new HttpHeaders();
        InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
        responseHeaders.setContentLength(contentLengthOfStream);
        responseHeaders.setContentType(MediaType.valueOf("application/pdf"));
        // just in case you need to support browsers
        responseHeaders.put("Content-Disposition", Collections.singletonList("attachment; filename=somefile.pdf"))
        return new ResponseEntity<InputStreamResource> (inputStreamResource,
                                   responseHeaders,
                                   HttpStatus.OK);
}
Reference :- https://stackoverflow.com/a/33877513/5802185 

Thursday, December 16, 2021

Can I Email… Useful tool when creating email templates

 While I’m 85% certain you’ve seen and used Can I Use…, I bet there is only a 13% chance that you’ve seen and used Can I Email…. It’s the same vibe—detailed support information for web platform features—except instead of support information for web browsers, it is email clients. Campaign Monitor has maintained a guide for a long time as well, but I admit I like the design style pioneered by Can I Use….

 

 

 

 

References Used :-  https://css-tricks.com/can-i-email/

 

 

 

 

 

 

 

 

 

Monday, October 11, 2021

Model Tree Structures in Mongo DB

Hope this  document will  help  to model   hierarchical or nested data relationships with mongoDB .

MongoDB allows various ways to use tree data structures to model large hierarchical or nested data relationships.

Tree data model for a sample hierarchy of categories.
Model Tree Structures with Parent References
Presents a data model that organizes documents in a tree-like structure by storing references to "parent" nodes in "child" nodes.
Model Tree Structures with Child References
Presents a data model that organizes documents in a tree-like structure by storing references to "child" nodes in "parent" nodes.
Model Tree Structures with an Array of Ancestors
Presents a data model that organizes documents in a tree-like structure by storing references to "parent" nodes and an array that stores all ancestors.
Model Tree Structures with Materialized Paths
Presents a data model that organizes documents in a tree-like structure by storing full relationship paths between documents. In addition to the tree node, each document stores the _id of the nodes ancestors or path as a string.
Model Tree Structures with Nested Sets
Presents a data model that organizes documents in a tree-like structure using the Nested Sets pattern. This optimizes discovering subtrees at the expense of tree mutability.
 
Reference  Used :-   https://docs.mongodb.com/manual/applications/data-models-tree-structures/
 

Sunday, August 29, 2021

Solve the challenges and pursue ICT career opportunities by showcasing your skills to the IT/BPM companies in Sri Lanka.

This is  some  thing  interesting  I  seen ,  for  our  career growth.

 These challenges are there for you to learn the basic skills required by any IT related profession. You should be able to lean and complete a single challenge within 1 or 2 days. Please solve the challenges in sequence. Once you solve a particular challenge you will have to submit the results and take a small assessment to demonstrate your understanding.

 

Solve the challenges and pursue ICT career opportunities by showcasing your skills to the IT/BPM companies in Sri Lanka. 

Monday, August 23, 2021

RabbitMQ vs Kafka | Trade-off's to choose one over other

Here  are  some  good videos  I  have seen  about  " RabbitMQ vs Kafka "



2.   RabbitMQ & Kafka  by  VMware Tanzu


Features of Kafka :- 




Some  important  tips captured  from  above  videos  are :-  



 




Version   1.0.1



Saturday, August 21, 2021

What does it mean by “Program to an interface” ?

 This  answer  is  fully  copied  from  stackoverflow  answer .

There are some wonderful answers on here to this questions that get into all sorts of great detail about interfaces and loosely coupling code, inversion of control and so on. There are some fairly heady discussions, so I'd like to take the opportunity to break things down a bit for understanding why an interface is useful.

When I first started getting exposed to interfaces, I too was confused about their relevance. I didn't understand why you needed them. If we're using a language like Java or C#, we already have inheritance and I viewed interfaces as a weaker form of inheritance and thought, "why bother?" In a sense I was right, you can think of interfaces as sort of a weak form of inheritance, but beyond that I finally understood their use as a language construct by thinking of them as a means of classifying common traits or behaviors that were exhibited by potentially many non-related classes of objects.

For example -- say you have a SIM game and have the following classes:

class HouseFly inherits Insect {
    void FlyAroundYourHead(){}
    void LandOnThings(){}
}

class Telemarketer inherits Person {
    void CallDuringDinner(){}
    void ContinueTalkingWhenYouSayNo(){}
}

Clearly, these two objects have nothing in common in terms of direct inheritance. But, you could say they are both annoying.

Let's say our game needs to have some sort of random thing that annoys the game player when they eat dinner. This could be a HouseFly or a Telemarketer or both -- but how do you allow for both with a single function? And how do you ask each different type of object to "do their annoying thing" in the same way?

The key to realize is that both a Telemarketer and HouseFly share a common loosely interpreted behavior even though they are nothing alike in terms of modeling them. So, let's make an interface that both can implement:

interface IPest {
    void BeAnnoying();
}

class HouseFly inherits Insect implements IPest {
    void FlyAroundYourHead(){}
    void LandOnThings(){}

    void BeAnnoying() {
        FlyAroundYourHead();
        LandOnThings();
    }
}

class Telemarketer inherits Person implements IPest {
    void CallDuringDinner(){}
    void ContinueTalkingWhenYouSayNo(){}

    void BeAnnoying() {
        CallDuringDinner();
        ContinueTalkingWhenYouSayNo();
    }
}

We now have two classes that can each be annoying in their own way. And they do not need to derive from the same base class and share common inherent characteristics -- they simply need to satisfy the contract of IPest -- that contract is simple. You just have to BeAnnoying. In this regard, we can model the following:

class DiningRoom {

    DiningRoom(Person[] diningPeople, IPest[] pests) { ... }

    void ServeDinner() {
        when diningPeople are eating,

        foreach pest in pests
        pest.BeAnnoying();
    }
}

Here we have a dining room that accepts a number of diners and a number of pests -- note the use of the interface. This means that in our little world, a member of the pests array could actually be a Telemarketer object or a HouseFly object.

The ServeDinner method is called when dinner is served and our people in the dining room are supposed to eat. In our little game, that's when our pests do their work -- each pest is instructed to be annoying by way of the IPest interface. In this way, we can easily have both Telemarketers and HouseFlys be annoying in each of their own ways -- we care only that we have something in the DiningRoom object that is a pest, we don't really care what it is and they could have nothing in common with other.

This very contrived pseudo-code example (that dragged on a lot longer than I anticipated) is simply meant to illustrate the kind of thing that finally turned the light on for me in terms of when we might use an interface. I apologize in advance for the silliness of the example, but hope that it helps in your understanding. And, to be sure, the other posted answers you've received here really cover the gamut of the use of interfaces today in design patterns and development methodologies.

 

 To add to the existing posts, sometimes coding to interfaces helps on large projects when developers work on separate components simultaneously. All you need is to define interfaces upfront and write code to them while other developers write code to the interface you are implementing.

 


 References Used  :-    Answer to this question


Version :-   1.0.0

Wednesday, August 18, 2021

Some Tips to Reduce GIT Conflicts

 When  you  are working  on  same  project  with  many  co-workers  , I think those  small  steps  will  be  reduce pain  of  resolving  GIT conflicts .

1.  Re-base  every  day as  you  can   from  remote branch which you are wanted to merge ,your  local  branch .

2. If  any  thing standard git conflict  resolving ways  you  tried didn't  works , you may  use  this way. Create  a  backup  of  your  current  project  and then  create  a local new  branch  from  remote  branch  which  you  wanted  merge to  finally . Then  copy  paste  your  changes  from backup project  to  new  branch .  You  have to  make  sure  all  your  changes are  copying  to  new  branch .  After  that  please  make  do some  testing  to  check  all  changes  are there .  Then  push  your  changes to remote .  Finally  create  a pull  request . I  think  this  way  may not  be  much  professional  , but  this  also  can use as  your final  try.


Version  1.0.0

How to send email using Spring Boot Application with Gmail SMTP Server

Sunday, August 15, 2021

Short notes on different development technologies by GoalKicker

This web site may be useful  to get good notes about  various technologies  .


https://goalkicker.com/

Thursday, July 29, 2021

Fix issues before they exist - SonarLint is an IDE extension

 This  extension is  really  useful to  improve  our  code  quality .

Fix issues before they exist

SonarLint is an IDE extension that helps you detect and fix quality issues as you write code.
Like a spell checker, SonarLint squiggles flaws so that they can be fixed before committing code.

 

 

 

https://www.sonarlint.org/

Wednesday, July 21, 2021

How to create a icon to run for application in Ubuntu

 1.  Go   to   root  folder and  then open  a  terminal there .  If  not  use  Ctrl  +  L   and  search  "/usr/share/applications"

2. Then  go  to  path  "/usr/share/applications

     root@roshans-HP-PrBook-G4:/usr/share/applications#

3. Then  we have  to  give  a  name  for   icon  name as  we want ,

    Here  my  icon  name  is   "intelJIdea"

   sudo  touch intelJIdea.desktop 

4. After  that   sudo vi   intelJIdea.desktop .Then    we  have  to add following  code  to  that  file  

    [Desktop Entry]
    Name=IntelliJ IDEA
    Comment=IntelliJ IDEA IDE
    Exec=/home/roshans/Documents/Software/idea-IC-211.7628.21/bin/idea.sh
    Icon=/home/roshans/Documents/Software/idea-IC-211.7628.21/bin/idea.png
    Terminal=false
    StartupNotify=true
    Type=Application
    Categories=Development;IDE;

5. Then  save  that  file using :wq

6. Then  you  will  be  able  to  find   icon   for  any  application  you  wanted  to  run  using  icon  in the   your  application  list.  

 

 

 


 

Saturday, June 26, 2021

Arrays Utility Class in Java

The Arrays is a utility class which can be found in the  java.util  package. It is very  useful class  and  following  are some of useful methods it has:

  • asList(): returns a fixed-size list backed by an array.
  • binarySearch(): searches for a specific value in an array. Returns the index of the element if found, or -1 if not found. Note that the array must be sorted first.
               int  indexWhichFound  =  Arrays.binarySearch(arrayToSearch,  keyWhichWantToFind);
  • copyOf(): copies a portion of the specified array to a new one. 
               Interger[]   trimmedArray    =   Arrays.copyOf(originalArray, newLength);
  • copyOfRange(): copies a specified range of an array to a new one.
                Interger[]   croppedArray    =   Arrays.copyOfRange(originalArray, startLength,  endLength); 
  • equals(): compares two arrays to determine if they are equal or not.
  • fill(): fills same values to all or some elements in an array.
  • sort(): sorts an array into ascending order.
                 void sort(X[] a)
                 void sort(X[] a, int fromIndex, int toIndex)
                 void sort(T[] a, Comparator<? super T> c)
                 void sort(T[] a, int fromIndex, int toIndex, Comparator<? super T> c)

In addition, the System.arraycopy() is an efficient method for copying elements from one array to another. Remember using this method instead of writing your own procedure because this method is very efficient. Arrays.copyOf(originalArray, newLength)  method  internally  uses that  method .Refer  this  document  for more  about  creating  a  copy  of  array. 

System.arraycopy(Object  copyFromArray, int startingPositionOfArrayToCopy,
                             Object  copyToArray, int landingPositionOfArrayCopy, int totalNumerOfComponentsToBeCopy)

So far I have walked you through a tour of arrays in Java. Here’s the summary for today:

  • An array is an object.
  • Elements in an array are accessed by index (0-based).
  • Advantage of array: very fast access to elements.
  • Disadvantage of array: fixed length, not appropriate if a dynamic container is required.
  • The java.util.Arrays class provides useful utility methods for working with arrays such as filling, searching and sorting.
  • The System.arraycopy() method provides an efficient mechanism for copying elements from one array to another.

 

References Used  :-  Notes about Arrays in Java

The AI Driven Software Developer, Optimize Innovate Transform

  The AI-Driven Software Developer: Optimize, Innovate, Transform": AI Transformation in Software Development : Understand how AI is re...