Tuesday, December 29, 2015

How to get keys from HashMap in Java

private Map<String, Integer> collection = new HashMap<String, Integer>();

collection.put("row #1", 1);
collection.put("row #2", 2);

for ( String key : collection.keySet() ) {
    System.out.println( key );
}

How to connect to the SDL Tridion 2011 core services client using JAVA?

  1. Create a new folder under your source project
  2. Open a terminal window and go to the JDK\bin folder
  3. Type the following ws-import command:
    wsimport -extension -keep -Xnocompile -d {location of the source folder} {Webservice URL}

  4. Create the authenticator class:
    import java.net.Authenticator;
    import java.net.PasswordAuthentication;

    public class BasicHttpAuthenticator extends Authenticator {

       private String user;
       private String password;

       public BasicHttpAuthenticator(String user, String password) {
          this.user = user;
          this.password = password;
       }

       @Override
       protected PasswordAuthentication getPasswordAuthentication() {
          return new PasswordAuthentication(user, password.toCharArray());
       }
    }

  5. Create the web service client class:
    import java.net.Authenticator;
    import java.net.URL;

    import javax.xml.namespace.QName;

    import com.sdltridion.contentmanager.coreservice._2011.CoreService2011;
    import com.sdltridion.contentmanager.coreservice._2011.ICoreService;
    import com.sdltridion.contentmanager.r6.UserData;

    public class Main {
       private static final QName Q_NAME = new QName("http://www.sdltridion.com/ContentManager/CoreService/2011", "CoreService2011");

       public static void main(String[] args) throws Exception {
          BasicHttpAuthenticator basicHttpAuthenticator = new BasicHttpAuthenticator({user}, {password});
          Authenticator.setDefault(basicHttpAuthenticator);

          URL url = new URL({Webservice URL});
          CoreService2011 service = new CoreService2011(url, Q_NAME);
          ICoreService client = service.getBasicHttp();

          UserData currentUser = client.getCurrentUser();
          System.out.println(String.format("'%s' %s",
          currentUser.getTitle().getValue(), currentUser.getId()));
    }
{user} is an account with access to the CMS
{password} is the account password
{Webservice URL} is the core service URL

Example:

Java version used for this project is Java 1.8.0_66-b17

{user}: administrator
{password}: h}S<77Sn
{Webservice URL}: http://www.blogger.com/webservices/CoreService2011.svc?singleWsdl
{location of the source folder}
     Windows: C:\source\CoreService2011\src
     Linux: /source/CoreService2011/src
JDK\bin folder: the default locations are
     Windows 64-bits: C:\Program Files\Java\jdk1.8.0_66\bin
     Linux: /usr/lib/jvm/java-8-oracle/bin

Structure of the project:
src
+--- BasicHttpAuthenticator.java
+--- Main.java

wsimport -extension -keep -Xnocompile -d /source/CoreService2011/src http://www.blogger.com/webservices/CoreService2011.svc?singleWsdl

import java.net.Authenticator;
import java.net.PasswordAuthentication;

public class BasicHttpAuthenticator extends Authenticator {

   private String user;
   private String password;

   public BasicHttpAuthenticator(String user, String password) {
      this.user = user;
      this.password = password;
   }

   @Override
   protected PasswordAuthentication getPasswordAuthentication() {
      return new PasswordAuthentication(user, password.toCharArray());
   }
}

import java.net.Authenticator;
import java.net.URL;

import javax.xml.namespace.QName;

import com.sdltridion.contentmanager.coreservice._2011.CoreService2011;
import com.sdltridion.contentmanager.coreservice._2011.ICoreService;
import com.sdltridion.contentmanager.r6.UserData;

public class Main {
   private static final QName Q_NAME = new QName("http://www.sdltridion.com/ContentManager/CoreService/2011", "CoreService2011");

   public static void main(String[] args) throws Exception {
      BasicHttpAuthenticator basicHttpAuthenticator = new BasicHttpAuthenticator("administrator", "h}S<77Sn");
      Authenticator.setDefault(basicHttpAuthenticator);

      URL url = new URL("http://www.blogger.com/webservices/CoreService2011.svc?singleWsdl");
      CoreService2011 service = new CoreService2011(url, Q_NAME);
      ICoreService client = service.getBasicHttp();

      UserData currentUser = client.getCurrentUser();
      System.out.println(String.format("'%s' %s", currentUser.getTitle().getValue(), currentUser.getId()));
   }
}

Source: http://yatb.mitza.net/2012/12/a-core-service-java-client.html

Friday, December 25, 2015

How to fix The server's host key is not cached in the registry. You have no guarantee that the server is the computer you think it is when Fetch/Pull/Push in SourceTree

Issue when you click Show Full Output

git -c diff.mnemonicprefix=false -c core.quotepath=false fetch origin
The server's host key is not cached in the registry. You
have no guarantee that the server is the computer you
think it is.
The server's rsa2 key fingerprint is:
ssh-rsa 2048 ...
If you trust this host, enter "y" to add the key to
PuTTY's cache and carry on connecting.
If you want to carry on connecting just once, without

adding the key to the cache, enter "n".
If you do not trust this host, press Return to abandon the
connection.

Fix

  1. Open command prompt and type:
    "C:\Program Files (x86)\ Atlassian\SourceTree\tools\putty\plink.exe" {server} 
  2. Accept to store key in cache
  3. Type the username to connect to the server
  4. Type the password
  5. Close command prompt
  6. Try to Fetch/Pull/Push again
{server} is where the GIT server is located

Example:

"C:\Program Files (x86)\ Atlassian\SourceTree\tools\putty\plink.exe" www.blogger.com

Source: http://stackoverflow.com/questions/32437659/cannot-pull-git-remote-repository-from-sourcetree

Thursday, October 29, 2015

How to resize a Ubuntu partition


This How To covers the following scenario:
GParted is showing that I have the following partitions

PartitionFile SystemSize
/dev/sda1ext492.09 GiB
/dev/sda2extended7.90 GiB
/dev/sda5linux-swap7.90 GiB
unallocatedunallocated107.91 GiB

My goal is to use the whole unallocated partition
  1. Add a device to the machine with the Ubuntu "burned" on it ( http://www.ubuntu.com/download/desktop/create-a-usb-stick-on-windows )
  2. Reboot the machine
  3. Click Try Ubuntu
  4. Press ALT + T
  5. Type the following command:

    sudo gparted

  6. Highlight the swap partition /dev/sda5
  7. In the menu, click Partition
  8. Click Swapoff
  9. Highlight the swap partition /dev/sda5
  10. In the menu, click Partition
  11. Click Delete
  12. Highlight the extended partition /dev/sda2
  13. In the menu, click Partition
  14. Click Delete
  15. Highlight the partition that you want to resize /dev/sda1
  16. In the menu, click Partition
  17. Click Resize/Move
  18. In Resize/Move /dev/sda1 window, expand the size to 100 GiB
  19. Click Resize/Move
  20. In the menu, click Partition
  21. Click New
  22. In Create new Partition window, change Create as to Extended Partition
  23. Click Add
  24. Highlight unallocated
  25. In the menu, click Partition
  26. Click New
  27. In Create new Partition window, change Create as to Logical Partition
  28. Change File System to linux-swap
  29. Click Add
  30. In the menu, click Edit
  31. Click Apply All Operations
  32. In Apply operations to device window, click Apply
  33. Click Close

Saturday, October 17, 2015

How to connect to the SDL Tridion 2011 core services client?

var binding = new WSHttpBinding {
     TransactionFlow = true,
     MaxReceivedMessageSize = 83886080,
     ReaderQuotas = { MaxStringContentLength = 83886080 },
     OpenTimeout = TimeSpan.FromMinutes(5),
     ReceiveTimeout = TimeSpan.FromMinutes(5),
     CloseTimeout = TimeSpan.FromMinutes(5),
     SendTimeout = TimeSpan.FromMinutes(5)
};

var address = new EndpointAddress("http://{domain}/webservices/CoreService2011.svc/wsHttp");

SessionAwareCoreServiceClient client = new SessionAwareCoreServiceClient(binding, address);

{domain} is the domain where the CMS Administration GUI is installed

Example: 

List all publications of where luizcgjr.blogspot.com is the domain that hosts the CMS Administration GUI

var  binding = new WSHttpBinding {
     TransactionFlow = true,
     MaxReceivedMessageSize = 83886080,
     ReaderQuotas = { MaxStringContentLength = 83886080 },
     OpenTimeout = TimeSpan.FromMinutes(5),    
     ReceiveTimeout = TimeSpan.FromMinutes(5),    
     CloseTimeout = TimeSpan.FromMinutes(5),    
     SendTimeout = TimeSpan.FromMinutes(5)
};

var address = new EndpointAddress("http://luizcgjr.blogspot.com/webservices/CoreService2011.svc/wsHttp");

using (SessionAwareCoreServiceClient client = new SessionAwareCoreServiceClient(binding, address)) {
     var publications = _client.GetSystemWideList(new PublicationsFilterData());    

     foreach (var publication in publications) {
          Console.WriteLine(publication.Title);
     }
}

How the item types in Tridion are organized?


  1. Publication
    1. Folder
      1. Folder
      2. Schema
      3. Component
      4. ComponentTemplate
      5. PageTemplate
      6. TargetGroup
      7. TemplateBuildingBlock
      8. VirtualFolder
    2. Structure Group
      1. StructureGroup
      2. Page
    3. Category
      1. Category
      2. Keyword

Wednesday, September 30, 2015

How to backup a single MySQL database?

  1. Open the Command Prompt (Windows)/Terminal (Linux)
  2. Type the following command:

    mysqldump -u {username} -p{password} -h {host} {databaseName} > {backup-name}.sql
{username} is the login that has access to connect to the database
{password} is the login's password
{host} is the server name where it is the database
{databaseName} is the database name
{backup-name} is the name back up file name

Example:

I want to backup the BAZINGA database located at the TheBigBangTheory host with the user name Sheldon and password Cooper and save it on Meemaw.sql  file.

mysqldump -u Sheldon -pCooper -h TheBigBangTheory BAZINGA > Meemaw.sql

Source: https://www.linode.com/docs/databases/mysql/back-up-your-mysql-databases

Friday, September 18, 2015

Thursday, September 17, 2015

How to do foreach in Java

List<String> collection = new ArrayList<String>();

collection.add("Hello");
collection.add("World");

for(String item:collection)
{
System.out.println(item);
}

Wednesday, September 16, 2015

How to check how much RAM you have installed in Linux


  1. Open terminal
  2. Type

    free -mt
This command will output the memory in megabytes

How to move the Eclipse workspace to another folder


  1. Close Eclipse
  2. Open the OS file manager (Example: Windows Explorer for Windows and Nautilus for Linux)
  3. Move the workspace folder to the new location
  4. Open Eclipse
  5. In the menu bar, click File
  6. Mouse over Switch Workspace
  7. Click Other...
  8. Select the new workspace folder location
  9. Click OK

Monday, September 14, 2015

How to fix web sites cannot be started unless both the Windows Activation Service (WAS) and the World Wide Web Publishing Service (W3SVC) are running IIS Error

IIS Error


Fix
  1. Open command prompt and type:

    net start w3svc

  2. Open IIS
  3. Start the site again


How to execute any PowerShell script in your development machine


  1. Open PowerShell ISE
  2. In command pane type:

    Set-ExecutionPolicy Unrestricted

  3. In Execution Policy Change window, click Yes
ATTENTION! This is only recommended for development machines.

How to remove duplicate XML nodes using PowerShell

catalog.xml
<?xml version="1.0" encoding="utf-8"?>
<CATALOG>
  <CD>
    <TITLE>Empire Burlesque</TITLE><ARTIST>Bob Dylan</ARTIST><COUNTRY>USA</COUNTRY><COMPANY>Columbia</COMPANY><PRICE>10.90</PRICE><YEAR>1985</YEAR>
  </CD>
  <CD>
    <TITLE>Hide your heart</TITLE><ARTIST>Bonnie Tyler</ARTIST><COUNTRY>UK</COUNTRY><COMPANY>CBS Records</COMPANY><PRICE>9.90</PRICE><YEAR>1988</YEAR>
  </CD>
  <CD>
    <TITLE>Greatest Hits</TITLE><ARTIST>Dolly Parton</ARTIST><COUNTRY>USA</COUNTRY><COMPANY>RCA</COMPANY><PRICE>9.90</PRICE><YEAR>1982</YEAR>
  </CD>
  <CD>
    <TITLE>Hide your heart</TITLE><ARTIST>Bonnie Tyler</ARTIST><COUNTRY>UK</COUNTRY><COMPANY>CBS Records</COMPANY><PRICE>9.90</PRICE><YEAR>1988</YEAR>
  </CD>
  <CD>
    <TITLE>Hide your heart</TITLE><ARTIST>Bonnie Tyler</ARTIST><COUNTRY>UK</COUNTRY><COMPANY>CBS Records</COMPANY><PRICE>9.90</PRICE><YEAR>1988</YEAR>
  </CD>
</CATALOG>

Code:
# Load XML file

$file = "catalog.xml"
$xml = [xml](Get-Content $file)

# Add the DuppieID attribute to the XML document

$i = 1
foreach($node in $xml.CATALOG.CD)
{  
    $node.SetAttribute("DuppieID", $i)
    $i++
}

# Parse the document and delete the duplicate nodes with the exception of the first occurrence

foreach($node in $xml.CATALOG.CD)
{  
    $duplicates = ($xml.CATALOG.CD | where {$_.TITLE -eq $node.TITLE})
   
    if($duplicates.length -gt 1)
    {
        for($i = 1; $i -lt $duplicates.length; $i++)
        {
            $element = $duplicates[$i]
            $nodeToRemove = $xml.SelectSingleNode("//CATALOG/CD[@DuppieID=" + $element.DuppieID + "]")
            $nodeToRemove.ParentNode.RemoveChild($nodeToRemove)
        }
    }
}

# Remove DuppieID attribute
   
foreach($node in $xml.CATALOG.CD)
{  
    $node.RemoveAttribute("DuppieID");
}

# Update the file

$xml.Save($file)

Source: http://klemmestad.com/2014/08/08/removing-duplicate-xml-nodes-using-powershell/

Wednesday, September 2, 2015

How to activate the tab auto-complete on a xrdp session in Xubuntu


  1. Open terminal
  2. Open the  ~/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-keyboard-shortcuts.xml using a text editor
  3. Find the node

    <property name="&lt;Super&gt;Tab" type="string" value="switch_window_key"/>

  4. Replace to

    <property name="&lt;Super&gt;Tab" type="string" value="empty"/>

  5. Save the file
  6. Restart the machine

How to find the largest files and folders in Linux


  1. Open terminal
  2. Type

    du -a /{folder} | sort -n -r | head -n {count}
{folder} is the starting location where you want to find the largest files and folders
{count} number of results you want to see

Example

Find the top 10 files of the whole file system
du -a / | sort -n -r | head -n 10

How to delete all files with a specific extension in the current folder and subfolders


  1. Open terminal
  2. Type the command

    find /{path}/ -type f -name "*.{extension}" -delete
{path} folder where the are the files that you want to delete
{extension} file extension that you want to delete

Example:

Delete all MPG files from /home/luizcgjr and its subfolders

find /home/luizcgjr/ -type f -name "*.mpg" -delete

Source: http://unix.stackexchange.com/questions/42020/how-can-i-delete-all-files-with-a-particular-extension-in-a-particular-folder

How to enable Remote Desktop connection on Xubuntu

  1. Open terminal
  2. Type the command

    sudo apt-get install xrdp

  3. Restart Xubuntu
  4. Once the machine is restarted, go to the machine where you want remote connect
  5. Open remote desktop client
  6. Connect to the machine where you installed the xrdp
  7. At the Login to xrdp window, select sesman-Xvnc for Module
  8. In username type the login that you use to logon to the machine locally
  9. In password type the login's password

  10. Click OK
Attention: this will create a new x Session and not mirror what are you current seeing in your remote machine. There are other solutions for that.

Thursday, August 20, 2015

How to resize a VDI disk in VirtualBox

  1. Shutdown the virtual machine where you want to resize the virtual disk
  2. Open Oracle VM VirtualBox Manager
  3. Highlight the virtual machine where you want to resize the virtual disk
  4. Click the Settings ribbon bar button
  5. In the virtual machine settings window, click Storage at the left bar menu
  6. In the Storage Tree section, highlight the virtual disk that you want to resize
  7. In the Information section, right-click the file path after Location:
  8. Click Copy
  9. Open the Command Prompt (Windows)/Terminal (Linux)
  10. Type the following command

    vboxmanage modifyhd {location-path} --resize {size}
{location-path} is the virtual disk location that you copied in step 8
{size} is the new virtual disk size in megabytes (for example: 1 Gb = 1024 Mb)

Example:

I want to resize my virtual disk to 100 Gb:

vboxmanage modifyhd "H:\VMs\Guest#1.vdi" --resize 102400

Thursday, August 13, 2015

How to overwriting local changes in GIT using Sourcetree


  1. Open Sourcetree
  2. Open repository 
  3. At the ribbon bar, click Terminal


  4. At the terminal window, type the following commands:

    git fetch --all
    git reset --hard {remote branch} (example: origin/master)
    git pull origin master