Java Code Examples for org.alfresco.util.ISO8601DateFormat#parse()

The following examples show how to use org.alfresco.util.ISO8601DateFormat#parse() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DateQuarterRouter.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Boolean routeNode(int numShards, int shardInstance, Node node)
{
    if(numShards <= 1)
    {
        return true;
    }

    String ISO8601Date = node.getShardPropertyValue();
    Date date = ISO8601DateFormat.parse(ISO8601Date);
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTime(date);
    int month = calendar.get(Calendar.MONTH);
    int year  = calendar.get(Calendar.YEAR);

    // Avoid using Math.ceil with Integer
    int countMonths = ((year * 12) + (month+1));
    int grouping = 3;
    int ceilGroupInstance = (countMonths + grouping - 1) / grouping;
    
    return ceilGroupInstance % numShards == shardInstance;
    
}
 
Example 2
Source File: WebScriptUtil.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static Date getDate(JSONObject json) throws ParseException
{
    if(json == null)
    {
        return null;
    }
    String dateTime = json.optString(DATE_TIME);
    if(dateTime == null)
    {
        return null;
    }
    String format = json.optString(FORMAT);
    if(format!= null && ISO8601.equals(format) == false)
    {
        SimpleDateFormat dateFormat = new SimpleDateFormat(format);
        return dateFormat.parse(dateTime);
    }
    return ISO8601DateFormat.parse(dateTime);
}
 
Example 3
Source File: AuditEntry.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static AuditEntry parseAuditEntry(JSONObject jsonObject)
{
    Long id = (Long) jsonObject.get("id");
    String auditApplicationId = (String) jsonObject.get("auditApplicationId");
    Map<String, Serializable> values = (Map<String, Serializable>) jsonObject.get("values");
    org.alfresco.rest.api.model.UserInfo createdByUser = null;
    JSONObject createdByUserJson = (JSONObject) jsonObject.get("createdByUser");
    if (createdByUserJson != null)
    {
        String userId = (String) createdByUserJson.get("id");
        String displayName = (String) createdByUserJson.get("displayName");
        createdByUser = new  org.alfresco.rest.api.model.UserInfo(userId,displayName,displayName);   
    }
    Date createdAt = ISO8601DateFormat.parse((String) jsonObject.get("createdAt"));

    AuditEntry auditEntry = new AuditEntry(id, auditApplicationId, createdByUser, createdAt, values);
    return auditEntry;
}
 
Example 4
Source File: FavouritesServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private PersonFavourite getFavouriteSite(String userName, SiteInfo siteInfo)
  {
  	PersonFavourite favourite = null;

String siteFavouritedKey = siteFavouritedKey(siteInfo);
String siteCreatedAtKey = siteCreatedAtKey(siteInfo);

Boolean isFavourited = false;
Serializable s = preferenceService.getPreference(userName, siteFavouritedKey);
if(s != null)
{
	if(s instanceof String)
	{
		isFavourited = Boolean.valueOf((String)s);
	}
	else if(s instanceof Boolean)
	{
		isFavourited = (Boolean)s;
	}
	else
	{
		throw new AlfrescoRuntimeException("Unexpected favourites preference value");
	}
}

if(isFavourited)
{
	String createdAtStr = (String)preferenceService.getPreference(userName, siteCreatedAtKey);
	Date createdAt = (createdAtStr == null ? null : ISO8601DateFormat.parse(createdAtStr));

	favourite = new PersonFavourite(userName, siteInfo.getNodeRef(), Type.SITE, siteInfo.getTitle(), createdAt);
}

return favourite;
  }
 
Example 5
Source File: FavouritesServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void extractFavouriteSite(String userName, Type type, Map<PersonFavouriteKey, PersonFavourite> sortedFavouriteNodes, Map<String, Serializable> preferences, String key)
  {
  	// preference value indicates whether the site has been favourited   	
  	Serializable pref = preferences.get(key);
  	Boolean isFavourite = (Boolean)pref;
if(isFavourite)
{
   	PrefKeys sitePrefKeys = getPrefKeys(Type.SITE);
	int length = sitePrefKeys.getSharePrefKey().length();
	String siteId = key.substring(length);

  		try
  		{
       	SiteInfo siteInfo = siteService.getSite(siteId);
       	if(siteInfo != null)
       	{
   			StringBuilder builder = new StringBuilder(sitePrefKeys.getAlfrescoPrefKey());
   			builder.append(siteId);
   			builder.append(".createdAt");
   			String createdAtPrefKey = builder.toString();
   			String createdAtStr = (String)preferences.get(createdAtPrefKey);
   			Date createdAt = null;
   			if(createdAtStr != null)
   			{
				createdAt = (createdAtStr != null ? ISO8601DateFormat.parse(createdAtStr): null);
   			}
       		PersonFavourite personFavourite = new PersonFavourite(userName, siteInfo.getNodeRef(), Type.SITE, siteId, createdAt);
       		sortedFavouriteNodes.put(personFavourite.getKey(), personFavourite);
       	}
  		}
  		catch(AccessDeniedException ex)
  		{
  			// the user no longer has access to this site, skip over the favourite
  			// TODO remove the favourite preference 
  			return;
  		}
  	}
  }
 
Example 6
Source File: DatePropertyValueComparator.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Date getDate(Serializable value) 
{
    if(value instanceof Date)
    {
        return (Date) value;
    } 
    else if(value instanceof String)
    {
        return ISO8601DateFormat.parse((String) value);
    } 
    throw new AlfrescoRuntimeException("Parameter 'compareValue' must be of type java.util.Date!");
}
 
Example 7
Source File: DateMonthRouter.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Boolean routeNode(int numShards, int shardInstance, Node node)
{
    if(numShards <= 1)
    {
        return true;
    }

    String ISO8601Date = node.getShardPropertyValue();

    if(ISO8601Date == null)
    {
        return dbidRouter.routeNode(numShards, shardInstance, node);
    }

    try
    {
        Date date = ISO8601DateFormat.parse(ISO8601Date);
        GregorianCalendar cal = new GregorianCalendar();
        cal.setTime(date);
        int month = cal.get(Calendar.MONTH);
        int year = cal.get(Calendar.YEAR);
        return ((((year * 12) + month) / grouping) % numShards) == shardInstance;
    }
    catch (Exception exception)
    {
        return dbidRouter.routeNode(numShards, shardInstance, node);
    }
}
 
Example 8
Source File: FavouritesServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
private Map<PersonFavouriteKey, PersonFavourite> extractFavouriteNodes(String userName, Type type, String nodes)
 {
 	PrefKeys prefKeys = getPrefKeys(type);
 	Map<PersonFavouriteKey, PersonFavourite> favouriteNodes = new HashMap<PersonFavouriteKey, PersonFavourite>();

     StringTokenizer st = new StringTokenizer(nodes, ",");
     while(st.hasMoreTokens())
     {
     	String nodeRefStr = st.nextToken();
     	nodeRefStr = nodeRefStr.trim();
     	if(!NodeRef.isNodeRef((String)nodeRefStr))
     	{
     		continue;
     	}

     	NodeRef nodeRef = new NodeRef((String)nodeRefStr);

     	if(!nodeService.exists(nodeRef))
     	{
     		continue;
     	}

if(permissionService.hasPermission(nodeRef, PermissionService.READ_PROPERTIES) == AccessStatus.DENIED)
{
	continue;
}

     	// get createdAt for this favourited node
     	// use ISO8601
StringBuilder builder = new StringBuilder(prefKeys.getAlfrescoPrefKey());
builder.append(nodeRef.toString());
builder.append(".createdAt");
String prefKey = builder.toString();
String createdAtStr = (String)preferenceService.getPreference(userName, prefKey);
Date createdAt = (createdAtStr != null ? ISO8601DateFormat.parse(createdAtStr): null);

     	String name = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);

     	PersonFavourite personFavourite = new PersonFavourite(userName, nodeRef, type, name, createdAt);
     	PersonFavouriteKey key = personFavourite.getKey();
     	favouriteNodes.put(key, personFavourite);
     }

     return favouriteNodes;
 }
 
Example 9
Source File: MapBasedQueryWalker.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected void processVariable(String propertyName, String propertyValue, int type)
{
    String localPropertyName = propertyName.replaceFirst("variables/", "");
    Object actualValue = null;
    DataTypeDefinition dataTypeDefinition = null;
    // variable scope global is default
    String scopeDef = "global";
    
    // look for variable scope
    if (localPropertyName.contains("local/"))
    {
        scopeDef = "local";
        localPropertyName = localPropertyName.replaceFirst("local/", "");
    }

    if (localPropertyName.contains("global/"))
    {
        localPropertyName = localPropertyName.replaceFirst("global/", "");
    }
    
    // look for variable type definition
    if ((propertyValue.contains("_") || propertyValue.contains(":")) && propertyValue.contains(" ")) 
    {
        int indexOfSpace = propertyValue.indexOf(' ');
        if ((propertyValue.contains("_") && indexOfSpace > propertyValue.indexOf("_")) || 
                (propertyValue.contains(":") && indexOfSpace > propertyValue.indexOf(":")))
        {
            String typeDef = propertyValue.substring(0, indexOfSpace);
            try
            {
                QName dataType = QName.createQName(typeDef.replace('_', ':'), namespaceService);
                dataTypeDefinition = dictionaryService.getDataType(dataType);
                propertyValue = propertyValue.substring(indexOfSpace + 1);
            }
            catch (Exception e)
            {
                throw new ApiException("Error translating propertyName " + propertyName + " with value " + propertyValue);
            }
        }
    }
    
    if (dataTypeDefinition != null && "java.util.Date".equalsIgnoreCase(dataTypeDefinition.getJavaClassName()))
    {
        // fix for different ISO 8601 Date format classes in Alfresco (org.alfresco.util and Spring Surf)
        actualValue = ISO8601DateFormat.parse(propertyValue);
    }
    else if (dataTypeDefinition != null)
    {
        actualValue = DefaultTypeConverter.INSTANCE.convert(dataTypeDefinition, propertyValue);
    }
    else 
    {
        actualValue = propertyValue;
    }
    
    variableProperties.add(new QueryVariableHolder(localPropertyName, type, actualValue, scopeDef));
}
 
Example 10
Source File: SOLRSerializerTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void trip( SOLRTypeConverter typeConverter, String iso, String zulu)
{
         Date testDate = ISO8601DateFormat.parse(iso);
         String strDate = typeConverter.INSTANCE.convert(String.class, testDate);
         assertEquals(zulu, strDate);
}