You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ka...@apache.org on 2013/08/10 20:14:23 UTC
svn commit: r1512813 -
/directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/MetaAttributeHandler.java
Author: kayyagari
Date: Sat Aug 10 18:14:23 2013
New Revision: 1512813
URL: http://svn.apache.org/r1512813
Log:
the meta attribute handler
Added:
directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/MetaAttributeHandler.java
Added: directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/MetaAttributeHandler.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/MetaAttributeHandler.java?rev=1512813&view=auto
==============================================================================
--- directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/MetaAttributeHandler.java (added)
+++ directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/MetaAttributeHandler.java Sat Aug 10 18:14:23 2013
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.scim.ldap.handlers;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ws.rs.core.PathSegment;
+
+import org.apache.directory.api.ldap.model.constants.SchemaConstants;
+import org.apache.directory.api.ldap.model.entry.Attribute;
+import org.apache.directory.api.ldap.model.entry.Entry;
+import org.apache.directory.api.ldap.model.exception.LdapException;
+import org.apache.directory.scim.AttributeHandler;
+import org.apache.directory.scim.ComplexAttribute;
+import org.apache.directory.scim.RequestContext;
+import org.apache.directory.scim.SimpleAttribute;
+import org.apache.directory.scim.User;
+import org.apache.directory.scim.schema.BaseType;
+import org.apache.directory.scim.util.ResourceUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * TODO MetaAttributeHandler.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class MetaAttributeHandler implements AttributeHandler
+{
+
+ private static final Logger LOG = LoggerFactory.getLogger( ActiveAttributeHandler.class );
+
+ @Override
+ public void handle( BaseType bt, Object srcResource, RequestContext ctx )
+ {
+ Entry entry = ( Entry ) srcResource;
+
+ try
+ {
+ List<SimpleAttribute> atList = new ArrayList<SimpleAttribute>();
+
+ Attribute atCreated = entry.get( SchemaConstants.CREATE_TIMESTAMP_AT );
+ String createTimestamp = null;
+ if( atCreated != null )
+ {
+ SimpleAttribute created = new SimpleAttribute( "created" );
+ createTimestamp = ResourceUtil.formatDate( atCreated.getString() );
+ created.setValue( createTimestamp );
+ atList.add( created );
+ }
+
+ Attribute atlastMod = entry.get( SchemaConstants.MODIFY_TIMESTAMP_AT );
+ SimpleAttribute lastModified = null;
+ if( atlastMod != null )
+ {
+ lastModified = new SimpleAttribute( "lastModified" );
+ lastModified.setValue( ResourceUtil.formatDate( atlastMod.getString() ) );
+ }
+ else if( createTimestamp != null )
+ {
+ lastModified = new SimpleAttribute( "lastModified" );
+ lastModified.setValue( createTimestamp );
+ }
+
+ if( atlastMod != null )
+ {
+ atList.add( lastModified );
+ }
+
+ User user = ctx.getUser();
+
+ SimpleAttribute location = new SimpleAttribute( "location" );
+ String locationVal = ctx.getUriInfo().getAbsolutePath().toString();
+ List<PathSegment> pathSegLst = ctx.getUriInfo().getPathSegments();
+ if( !pathSegLst.isEmpty() )
+ {
+ locationVal = locationVal.replace( pathSegLst.get( pathSegLst.size() -1 ).getPath(), "" );
+ }
+
+ location.setValue( locationVal + user.getId() );
+ atList.add( location );
+
+ ComplexAttribute ct = new ComplexAttribute( bt.getName(), atList );
+ user.addAttribute( bt.getUri(), ct );
+ }
+ catch( LdapException e )
+ {
+ LOG.warn( "Failed while creating meta attribute", e );
+ }
+
+ }
+
+}