Java Code Examples for org.springframework.extensions.surf.util.ParameterCheck#mandatoryString()

The following examples show how to use org.springframework.extensions.surf.util.ParameterCheck#mandatoryString() . 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: ActivityServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public List<FeedControl> getFeedControls(String userId)
{
    ParameterCheck.mandatoryString("userId", userId);
    
    if (! userNamesAreCaseSensitive)
    {
        userId = userId.toLowerCase();
    }
    
    String currentUser = getCurrentUser();
    
    if ((currentUser == null) || 
        (! ((authorityService.isAdminAuthority(currentUser)) ||
            (currentUser.equals(userId)) ||
            (AuthenticationUtil.getSystemUserName().equals(this.tenantService.getBaseNameUser(currentUser))))))
    {
        throw new AlfrescoRuntimeException("Current user " + currentUser + " is not permitted to get feed controls for " + userId);
    }
    
    return getFeedControlsImpl(userId);
}
 
Example 2
Source File: People.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Create a Person with the given user name, firstName, lastName and emailAddress
 * 
 * @param userName the user name of the person to create
 * @return the person node (type cm:person) created or null if the user name already exists
 */
public ScriptNode createPerson(String userName, String firstName, String lastName, String emailAddress)
{
    ParameterCheck.mandatoryString("userName", userName);
    ParameterCheck.mandatoryString("firstName", firstName);
    ParameterCheck.mandatoryString("emailAddress", emailAddress);
    
    ScriptNode person = null;
    
    PropertyMap properties = new PropertyMap();
    properties.put(ContentModel.PROP_USERNAME, userName);
    properties.put(ContentModel.PROP_FIRSTNAME, firstName);
    properties.put(ContentModel.PROP_LASTNAME, lastName);
    properties.put(ContentModel.PROP_EMAIL, emailAddress);
    
    if (!personService.personExists(userName))
    {
        NodeRef personRef = personService.createPerson(properties);
        person = new ScriptNode(personRef, services, getScope()); 
    }
    
    return person;
}
 
Example 3
Source File: People.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Create a Person with the given user name
 * 
 * @param userName the user name of the person to create
 * @return the person node (type cm:person) created or null if the user name already exists
 */
public ScriptNode createPerson(String userName)
{
    ParameterCheck.mandatoryString("userName", userName);
    
    ScriptNode person = null;
    
    PropertyMap properties = new PropertyMap();
    properties.put(ContentModel.PROP_USERNAME, userName);
    
    if (!personService.personExists(userName))
    {
        NodeRef personRef = personService.createPerson(properties); 
        person = new ScriptNode(personRef, services, getScope()); 
    }
    
    return person;
}
 
Example 4
Source File: ScriptNode.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Re-sets the type of the node. Can be called in order specialise a node to a sub-type. This should be used
 * with caution since calling it changes the type of the node and thus* implies a different set of aspects,
 * properties and associations. It is the responsibility of the caller to ensure that the node is in a
 * approriate state after changing the type.
 * 
 * @param type Type to specialize the node
 * 
 * @return true if successful, false otherwise
 */
public boolean specializeType(String type)
{
    ParameterCheck.mandatoryString("Type", type);
    
    QName qnameType = createQName(type);
    
    // Ensure that we are performing a specialise
    if (getQNameType().equals(qnameType) == false &&
            this.services.getDictionaryService().isSubClass(qnameType, getQNameType()) == true)
    {
        // Specialise the type of the node
        this.nodeService.setType(this.nodeRef, qnameType);
        this.type = qnameType;
        
        return true;
    }
    return false;
}
 
Example 5
Source File: SiteServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @see org.alfresco.service.cmr.site.SiteService#getContainer(java.lang.String, String)
 */
public NodeRef getContainer(String shortName, String componentId)
{
    ParameterCheck.mandatoryString("componentId", componentId);

    // retrieve site
    NodeRef siteNodeRef = getSiteNodeRef(shortName);
    if (siteNodeRef == null)
    {
       throw new SiteDoesNotExistException(shortName);
    }

    // retrieve component folder within site
    // NOTE: component id is used for folder name
    NodeRef containerNodeRef = null;
    try
    {
        containerNodeRef = findContainer(siteNodeRef, componentId);
    } 
    catch (FileNotFoundException e)
    {
        //NOOP
    }

    return containerNodeRef;
}
 
Example 6
Source File: People.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Gets the Group given the group name
 * 
 * @param groupName  name of group to get
 * @return  the group node (type usr:authorityContainer) or null if no such group exists
 */
public ScriptNode getGroup(String groupName)
{
    ParameterCheck.mandatoryString("GroupName", groupName);
    ScriptNode group = null;
    NodeRef groupRef = authorityDAO.getAuthorityNodeRefOrNull(groupName);
    if (groupRef != null)
    {
        group = new ScriptNode(groupRef, services, getScope());
    }
    return group;
}
 
Example 7
Source File: People.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Faster helper when the script just wants to build the Full name for a person.
 * Avoids complete getProperties() retrieval for a cm:person.
 * 
 * @param username  the username of the person to get Full name for
 * @return full name for a person or null if the user does not exist in the system.
 */
public String getPersonFullName(final String username)
{
    String name = null;
    ParameterCheck.mandatoryString("Username", username);
    final NodeRef personRef = personService.getPersonOrNull(username);
    if (personRef != null)
    {
        final NodeService nodeService = services.getNodeService();
        final String firstName = (String)nodeService.getProperty(personRef, ContentModel.PROP_FIRSTNAME);
        final String lastName = (String)nodeService.getProperty(personRef, ContentModel.PROP_LASTNAME);
        name = (firstName != null ? firstName + " " : "") + (lastName != null ? lastName : "");
    }
    return name;
}
 
Example 8
Source File: ScriptNode.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Remove a permission for ALL user from the node.
 * 
 * @param permission Permission to remove @see org.alfresco.service.cmr.security.PermissionService
 */
public void removePermission(String permission)
{
    ParameterCheck.mandatoryString("Permission Name", permission);
    this.services.getPermissionService().deletePermission(
            this.nodeRef, PermissionService.ALL_AUTHORITIES, permission);
}
 
Example 9
Source File: ScriptNode.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @param type  The qname type to test this object against (fully qualified or short-name form)
 * @return true if this Node is a sub-type of the specified class (or itself of that class)
 */
public boolean isSubType(String type)
{
    ParameterCheck.mandatoryString("Type", type);
    
    QName qnameType = createQName(type);
    
    return this.services.getDictionaryService().isSubClass(getQNameType(), qnameType);
}
 
Example 10
Source File: People.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Set a password for the given user. Note that only an administrator
 * can perform this action, otherwise it will be ignored.
 * 
 * @param userName          Username to change password for
 * @param password          Password to set
 */
public void setPassword(String userName, String password)
{
    ParameterCheck.mandatoryString("userName", userName);
    ParameterCheck.mandatoryString("password", password);
    
    MutableAuthenticationService authService = this.services.getAuthenticationService();
    if (this.authorityService.hasAdminAuthority() && (userName.equalsIgnoreCase(authService.getCurrentUserName()) == false))
    {
        authService.setAuthentication(userName, password.toCharArray());
    }
}
 
Example 11
Source File: AbstractTenantAdminDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void deleteTenant(String tenantDomain)
{
    ParameterCheck.mandatoryString("tenantDomain", tenantDomain);
    
    // force lower-case on delete
    tenantDomain = tenantDomain.toLowerCase();
    
    int deleted = tenantEntityCache.deleteByKey(tenantDomain);
    if (deleted < 1)
    {
        throw new ConcurrencyFailureException("TenantEntity " + tenantDomain + " no longer exists");
    }
}
 
Example 12
Source File: ScriptNode.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Create a new folder (cm:folder) node as a child of this node.
 * 
 * Beware: Any unsaved property changes will be lost when this is called.  To preserve property changes call {@link #save()} first.
 *    
 * @param name Name of the folder to create
 * @param type Type of the folder to create (if null, defaults to ContentModel.TYPE_FOLDER)
 * 
 * @return Newly created Node or null if failed to create.
 */
public ScriptNode createFolder(String name, String type)
{
    ParameterCheck.mandatoryString("Node Name", name);
    
    FileInfo fileInfo = this.services.getFileFolderService().create(
            this.nodeRef, name, type == null ? ContentModel.TYPE_FOLDER : createQName(type));
    
    reset();
    
    return newInstance(fileInfo.getNodeRef(), this.services, this.scope);
}
 
Example 13
Source File: AbstractContentTransformer.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @deprecated use version with extra sourceSize parameter.
 */
public boolean isTransformable(String sourceMimetype, String targetMimetype, TransformationOptions options)
{
    ParameterCheck.mandatoryString("sourceMimetype", sourceMimetype);
    ParameterCheck.mandatoryString("targetMimetype", targetMimetype);
    
    double reliability = getReliability(sourceMimetype, targetMimetype);
    boolean result = true;
    if (reliability <= 0.0)
    {
        result = false;
    }
    return result;
}
 
Example 14
Source File: People.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Gets the Person given the username
 * 
 * @param username  the username of the person to get
 * @return the person node (type cm:person) or null if no such person exists 
 */
public TemplateNode getPerson(String username)
{
    ParameterCheck.mandatoryString("Username", username);
    TemplateNode person = null;
    if (personService.personExists(username))
    {
        NodeRef personRef = personService.getPerson(username);
        person = new TemplateNode(personRef, services, getTemplateImageResolver());
    }
    return person;
}
 
Example 15
Source File: ScriptNode.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Remove a permission for the specified authority (e.g. username or group) from the node.
 * 
 * @param permission Permission to remove @see org.alfresco.service.cmr.security.PermissionService
 * @param authority  Authority (generally a username or group name) to apply the permission for
 */
public void removePermission(String permission, String authority)
{
    ParameterCheck.mandatoryString("Permission Name", permission);
    ParameterCheck.mandatoryString("Authority", authority);
    this.services.getPermissionService().deletePermission(
            this.nodeRef, authority, permission);
}
 
Example 16
Source File: XPathMetadataExtracter.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings("rawtypes")
public Iterator getPrefixes(String namespaceURI)
{
    ParameterCheck.mandatoryString("namespaceURI", namespaceURI);
    List<String> prefixes = new ArrayList<String>(2);
    for (Map.Entry<String, String> entry : namespacesByPrefix.entrySet())
    {
        if (namespaceURI.equals(entry.getValue()))
        {
            prefixes.add(entry.getKey());
        }
    }
    return prefixes.iterator();
}
 
Example 17
Source File: People.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Change the password for the currently logged in user.
 * Old password must be supplied.
 *  
 * @param oldPassword       Old user password
 * @param newPassword       New user password
 */
public void changePassword(String oldPassword, String newPassword)
{
    ParameterCheck.mandatoryString("oldPassword", oldPassword);
    ParameterCheck.mandatoryString("newPassword", newPassword);
    
    this.services.getAuthenticationService().updateAuthentication(
            AuthenticationUtil.getFullyAuthenticatedUser(), oldPassword.toCharArray(), newPassword.toCharArray());
}
 
Example 18
Source File: SiteServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @see org.alfresco.service.cmr.site.SiteService#createContainer(java.lang.String,
 *      java.lang.String, org.alfresco.service.namespace.QName,
 *      java.util.Map)
 */
public NodeRef createContainer(String shortName, 
                               String componentId,
                               QName containerType, 
                               Map<QName, Serializable> containerProperties)
{
    // Check for the component id
    ParameterCheck.mandatoryString("componentId", componentId);

    // use the correct container for doclib
    // MNT-15743
    componentId = componentId.toLowerCase().equals(DOCUMENT_LIBRARY.toLowerCase()) ? DOCUMENT_LIBRARY : componentId;

    // retrieve site
    NodeRef siteNodeRef = getSiteNodeRef(shortName);
    if (siteNodeRef == null)
    {
       throw new SiteDoesNotExistException(shortName);
    }
    
    // Update the isPublic flag
    SiteVisibility siteVisibility = getSiteVisibility(siteNodeRef);

    // retrieve component folder within site
    NodeRef containerNodeRef = null;
    try
    {
        containerNodeRef = findContainer(siteNodeRef, componentId);
    } 
    catch (FileNotFoundException e)
    {
        //NOOP
    }

    // create the container node reference
    if (containerNodeRef == null)
    {
        if (containerType == null)
        {
            containerType = ContentModel.TYPE_FOLDER;
        }

        // create component folder
        FileInfo fileInfo = fileFolderService.create(siteNodeRef,
                componentId, containerType);

        // Get the created container
        containerNodeRef = fileInfo.getNodeRef();

        // Set the properties if they have been provided
        if (containerProperties != null)
        {
            Map<QName, Serializable> props = this.directNodeService
                    .getProperties(containerNodeRef);
            props.putAll(containerProperties);
            this.nodeService.setProperties(containerNodeRef, props);
        }

        // Add the container aspect
        Map<QName, Serializable> aspectProps = new HashMap<QName, Serializable>(1, 1.0f);
        aspectProps.put(SiteModel.PROP_COMPONENT_ID, componentId);
        this.nodeService.addAspect(containerNodeRef, ASPECT_SITE_CONTAINER,
                aspectProps);
        
        // Set permissions on the container
        if(SiteVisibility.MODERATED.equals(siteVisibility))
        {
            setModeratedPermissions(shortName, containerNodeRef);
        }
        else if (SiteVisibility.PRIVATE.equals(siteVisibility))
        {
            setPrivatePermissions(shortName, containerNodeRef);
        }
        
        // Make the container a tag scope
        this.taggingService.addTagScope(containerNodeRef);
    }

    return containerNodeRef;
}
 
Example 19
Source File: RepoAdminServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public NodeRef deployModel(InputStream modelStream, String modelFileName, boolean activate)
{
    try
    {   
        // Check that all the passed values are not null
        ParameterCheck.mandatory("ModelStream", modelStream);
        ParameterCheck.mandatoryString("ModelFileName", modelFileName);
        
        Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>();
        contentProps.put(ContentModel.PROP_NAME, modelFileName);
        
        StoreRef storeRef = repoModelsLocation.getStoreRef();
        NodeRef rootNode = nodeService.getRootNode(storeRef);
        
        List<NodeRef> nodeRefs = searchService.selectNodes(rootNode, repoModelsLocation.getPath(), null, namespaceService, false);
        
        if (nodeRefs.size() == 0)
        {
            throw new AlfrescoRuntimeException(MODELS_LOCATION_NOT_FOUND, new Object[] { repoModelsLocation.getPath() });
        }
        else if (nodeRefs.size() > 1)
        {
            // unexpected: should not find multiple nodes with same name
            throw new AlfrescoRuntimeException(MODELS_LOCATION_MULTIPLE_FOUND, new Object[] { repoModelsLocation.getPath() });
        }
        
        NodeRef customModelsSpaceNodeRef = nodeRefs.get(0);
        
        nodeRefs = searchService.selectNodes(customModelsSpaceNodeRef, "*[@cm:name='"+modelFileName+"' and "+defaultSubtypeOfDictionaryModel+"]", null, namespaceService, false);
        
        NodeRef modelNodeRef = null;
            
        if (nodeRefs.size() == 1)
        {
            // re-deploy existing model to the repository       
            
            modelNodeRef = nodeRefs.get(0);
        }
        else
        {
            // deploy new model to the repository
            
            try
            {
                // note: dictionary model type has associated policies that will be invoked
                ChildAssociationRef association = nodeService.createNode(customModelsSpaceNodeRef,
                        ContentModel.ASSOC_CONTAINS,
                        QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, modelFileName),
                        ContentModel.TYPE_DICTIONARY_MODEL,
                        contentProps); // also invokes policies for DictionaryModelType - e.g. onUpdateProperties
                            
                modelNodeRef = association.getChildRef();
            }
            catch (DuplicateChildNodeNameException dcnne)
            {
                String msg = "Model already exists: "+modelFileName+" - "+dcnne;
                logger.warn(msg);

                // for now, assume concurrency failure
                throw new ConcurrencyFailureException(getLocalisedMessage(MODEL_EXISTS, modelFileName));
            }
            
            // add titled aspect (for Web Client display)
            Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>();
            titledProps.put(ContentModel.PROP_TITLE, modelFileName);
            titledProps.put(ContentModel.PROP_DESCRIPTION, modelFileName);
            nodeService.addAspect(modelNodeRef, ContentModel.ASPECT_TITLED, titledProps);
            
            // add versionable aspect (set auto-version)
            Map<QName, Serializable> versionProps = new HashMap<QName, Serializable>();
            versionProps.put(ContentModel.PROP_AUTO_VERSION, true);
            nodeService.addAspect(modelNodeRef, ContentModel.ASPECT_VERSIONABLE, versionProps);
        }
        
        ContentWriter writer = contentService.getWriter(modelNodeRef, ContentModel.PROP_CONTENT, true);

        writer.setMimetype(MimetypeMap.MIMETYPE_XML);
        writer.setEncoding("UTF-8");
        
        writer.putContent(modelStream); // also invokes policies for DictionaryModelType - e.g. onContentUpdate
        modelStream.close();
        
        // activate the model
        nodeService.setProperty(modelNodeRef, ContentModel.PROP_MODEL_ACTIVE, Boolean.valueOf(activate));
        
        // note: model will be loaded as part of DictionaryModelType.beforeCommit()

        return modelNodeRef;
    }
    catch (Throwable e)
    {
        throw new AlfrescoRuntimeException(MODEL_DEPLOYMENT_FAILED, e);
    }     
}
 
Example 20
Source File: RepoAdminServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
private QName activateOrDeactivate(String modelFileName, boolean activate)
{
    // Check that all the passed values are not null        
    ParameterCheck.mandatoryString("modelFileName", modelFileName);

    StoreRef storeRef = repoModelsLocation.getStoreRef();          
    NodeRef rootNode = nodeService.getRootNode(storeRef);
    
    List<NodeRef> nodeRefs = searchService.selectNodes(rootNode, repoModelsLocation.getPath()+"//.[@cm:name='"+modelFileName+"' and "+defaultSubtypeOfDictionaryModel+"]", null, namespaceService, false);
    
    if (nodeRefs.size() == 0)
    {
        throw new AlfrescoRuntimeException(MODEL_NOT_FOUND, new Object[] { modelFileName });
    }
    else if (nodeRefs.size() > 1)
    {
        // unexpected: should not find multiple nodes with same name
        throw new AlfrescoRuntimeException(MODELS_MULTIPLE_FOUND, new Object[] { modelFileName });
    }
    
    NodeRef modelNodeRef = nodeRefs.get(0);
    
    boolean isActive = false;
    Boolean value = (Boolean)nodeService.getProperty(modelNodeRef, ContentModel.PROP_MODEL_ACTIVE);
    if (value != null)
    {
        isActive = value.booleanValue();
    }
    
    QName modelQName = (QName)nodeService.getProperty(modelNodeRef, ContentModel.PROP_MODEL_NAME);
    
    ModelDefinition modelDef = null;
    if (modelQName != null)
    {
     try
     {
     	modelDef = dictionaryDAO.getModel(modelQName);
     }
     catch (DictionaryException e)
     {
     	logger.warn(e);
     }
    }
    
    if (activate) 
    {
    	// activate
    	if (isActive)
    	{
     	if (modelDef != null)
     	{
     		// model is already activated
                throw new AlfrescoRuntimeException(MODEL_ALREADY_ACTIVATED, new Object[] { modelQName });
     	}
     	else
     	{
     		logger.warn("Model is set to active but not loaded in Dictionary - trying to load...");
     	}
    	}
    	else
    	{
     	if (modelDef != null)
     	{
     		logger.warn("Model is loaded in Dictionary but is not set to active - trying to activate...");
     	}
    	}
    }
    else
    {
    	// deactivate
    	if (!isActive)
    	{
     	if (modelDef == null)
     	{
     		// model is already deactivated
                throw new AlfrescoRuntimeException(MODEL_ALREADY_DEACTIVATED, new Object[] { modelQName });
     	}
     	else
     	{
     		logger.warn("Model is set to inactive but loaded in Dictionary - trying to unload...");
     	}
    	}
    	else
    	{
     	if (modelDef == null)
     	{
     		logger.warn("Model is not loaded in Dictionary but is set to active - trying to deactivate...");
     	}
    	}
    }
     
    // activate/deactivate the model 
    nodeService.setProperty(modelNodeRef, ContentModel.PROP_MODEL_ACTIVE, new Boolean(activate));
    
    // note: model will be loaded/unloaded as part of DictionaryModelType.beforeCommit()
    return modelQName;
}