package org.slc.sli.common.util.uuid;

import java.util.Random;

import com.fasterxml.uuid.EthernetAddress;
import com.fasterxml.uuid.Generators;
import com.fasterxml.uuid.impl.TimeBasedGenerator;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

/**
 * Generates Type 1 (time-based) UUIDs, preceeded by a shard key 'YYYYRR-'.
 *
 * @author wscott
 */
@Component
@Qualifier("shardType1UUIDGeneratorStrategy")
public class ShardType1UUIDGeneratorStrategy implements UUIDGeneratorStrategy {

    private TimeBasedGenerator generator = Generators.timeBasedGenerator(EthernetAddress.fromInterface());
    Random r = new Random();

    /**
     * Generate a shardable type 1 random UUID .
     */
    @Override
    public String randomUUID() {
        char c1 = (char) (r.nextInt(26) + 'a');
        char c2 = (char) (r.nextInt(26) + 'a');
        return "" + new DateTime().getYear() + c1 + c2 + "-" + generator.generate();
    }

}

@@ -48,153 +48,31 @@
 ava.
-util.Random;%0A%0Aimport com.fasterxml.uuid.EthernetAddress;%0Aimport com.fasterxml.uuid.Generators;%0Aimport com.fasterxml.uuid.impl.TimeBasedGenerator;
+security.SecureRandom;%0A
 %0Aimp
@@ -212,16 +212,149 @@
 onent;%0A%0A
+import com.fasterxml.uuid.EthernetAddress;%0Aimport com.fasterxml.uuid.Generators;%0Aimport com.fasterxml.uuid.impl.TimeBasedGenerator;%0A%0A
 /**%0A * G
@@ -587,16 +587,20 @@
 ategy %7B%0A
+    
 %0A    pri
@@ -703,16 +703,22 @@
 ));%0A    
+Secure
 Random r
@@ -724,16 +724,22 @@
 r = new 
+Secure
 Random()
@@ -853,16 +853,69 @@
 UID() %7B%0A
+        StringBuilder builder = new StringBuilder();%0A
         
@@ -1014,20 +1014,23 @@
     
-return %22%22 + 
+builder.append(
 new 
@@ -1053,54 +1053,191 @@
 ar()
- + c1 + c2 + %22-%22 + generator.generate();%0A    %7D%0A
+);%0A        builder.append(c1);%0A        builder.append(c2);%0A        builder.append(generator.generate().toString());%0A        String uuid = builder.toString();%0A        return uuid;%0A    %7D
 %0A%7D%0A

use string builder and secure random in shard type 1 uuid generator strategy