Java Code Examples for org.springframework.extensions.surf.util.ParameterCheck#mandatory()
The following examples show how to use
org.springframework.extensions.surf.util.ParameterCheck#mandatory() .
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: AbstractTenantAdminDAOImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@Override public TenantEntity createTenant(TenantEntity entity) { ParameterCheck.mandatory("entity", entity); ParameterCheck.mandatoryString("entity.tenantDomain", entity.getTenantDomain()); if (entity.getEnabled() == null) { entity.setEnabled(true); } // force lower-case on create entity.setTenantDomain(entity.getTenantDomain().toLowerCase()); entity.setVersion(0L); Pair<String, TenantEntity> entityPair = tenantEntityCache.getOrCreateByValue(entity); return entityPair.getSecond(); }
Example 2
Source File: TypeConverter.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 6 votes |
/** * General conversion method to Object types (note it cannot support * conversion to primary types due the restrictions of reflection. Use the * static conversion methods to primitive types) * * @param propertyType - the target property type * @param value - the value to be converted * @return - the converted value as the correct type */ public final Object convert(DataTypeDefinition propertyType, Object value) { ParameterCheck.mandatory("Property type definition", propertyType); // Convert property type to java class Class<?> javaClass = null; String javaClassName = propertyType.getJavaClassName(); try { javaClass = Class.forName(javaClassName); } catch (ClassNotFoundException e) { throw new DictionaryException("Java class " + javaClassName + " of property type " + propertyType.getName() + " is invalid", e); } return convert(javaClass, value); }
Example 3
Source File: AbstractAclCrudDAOImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
public Permission createPermission(PermissionReference permissionReference) { ParameterCheck.mandatory("permissionReference", permissionReference); PermissionEntity entity = null; // Get the persistent ID for the QName Pair<Long, QName> qnamePair = qnameDAO.getOrCreateQName(permissionReference.getQName()); if (qnamePair != null) { Long qnameId = qnamePair.getFirst(); entity = new PermissionEntity(qnameId, permissionReference.getName()); entity.setVersion(0L); Pair<Long, PermissionEntity> entityPair = permissionEntityCache.getOrCreateByValue(entity); entity = entityPair.getSecond(); } return entity; }
Example 4
Source File: AuditComponentImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
private Long getApplicationId(String applicationName) { ParameterCheck.mandatory("applicationName", applicationName); AlfrescoTransactionSupport.checkTransactionReadState(true); AuditApplication application = auditModelRegistry.getAuditApplicationByName(applicationName); if (application == null) { if (logger.isDebugEnabled()) { logger.debug("No audit application named '" + applicationName + "' has been registered."); } return null; } return application.getApplicationId(); }
Example 5
Source File: SolrFacetConfig.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
public SolrFacetConfig(Properties rawProperties, String inheritanceOrder) { ParameterCheck.mandatory("rawProperties", rawProperties); ParameterCheck.mandatory("inheritanceOrder", inheritanceOrder); this.rawProperties = rawProperties; String[] order = inheritanceOrder.split(","); this.propInheritanceOrder = new LinkedHashSet<>(order.length); for (String ord : order) { if (ord.length() > 0) { this.propInheritanceOrder.add(ord); } } }
Example 6
Source File: PolicyComponentImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
public BehaviourDefinition<ClassBehaviourBinding> bindClassBehaviour(QName policy, QName classRef, Behaviour behaviour) { // Validate arguments ParameterCheck.mandatory("Policy", policy); ParameterCheck.mandatory("Class Reference", classRef); ParameterCheck.mandatory("Behaviour", behaviour); // Validate Binding ClassDefinition classDefinition = dictionary.getClass(classRef); if (classDefinition == null) { throw new IllegalArgumentException("Class " + classRef + " has not been defined in the data dictionary"); } // Create behaviour definition and bind to policy ClassBehaviourBinding binding = new ClassBehaviourBinding(dictionary, classRef); BehaviourDefinition<ClassBehaviourBinding> definition = createBehaviourDefinition(PolicyType.Class, policy, binding, behaviour); getClassBehaviourIndex(policy).putClassBehaviour(definition); if (logger.isInfoEnabled()) logger.info("Bound " + behaviour + " to policy " + policy + " for class " + classRef); return definition; }
Example 7
Source File: ImporterComponent.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Get Node Reference from Location * * @param location the location to extract node reference from * @param binding import configuration * @return node reference */ private NodeRef getNodeRef(Location location, ImporterBinding binding) { ParameterCheck.mandatory("Location", location); // Establish node to import within NodeRef nodeRef = location.getNodeRef(); if (nodeRef == null) { // If a specific node has not been provided, default to the root nodeRef = nodeService.getRootNode(location.getStoreRef()); } // Resolve to path within node, if one specified String path = location.getPath(); if (path != null && path.length() >0) { // Create a valid path and search path = bindPlaceHolder(path, binding); path = createValidPath(path); List<NodeRef> nodeRefs = searchService.selectNodes(nodeRef, path, null, namespaceService, false); if (nodeRefs.size() == 0) { throw new ImporterException("Path " + path + " within node " + nodeRef + " does not exist - the path must resolve to a valid location"); } if (nodeRefs.size() > 1) { throw new ImporterException("Path " + path + " within node " + nodeRef + " found too many locations - the path must resolve to one location"); } nodeRef = nodeRefs.get(0); } // TODO: Check Node actually exists return nodeRef; }
Example 8
Source File: ContentSizeBucketsDisplayHandler.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public ContentSizeBucketsDisplayHandler(Set<String> facetQueryFields, LinkedHashMap<String, String> sizeBucketsMap) { ParameterCheck.mandatory("facetQueryFields", facetQueryFields); ParameterCheck.mandatory("sizeBucketsMap", sizeBucketsMap); this.supportedFieldFacets = Collections.unmodifiableSet(facetQueryFields); facetLabelMap = new HashMap<>(sizeBucketsMap.size()); Map<String, List<String>> facetQueries = new LinkedHashMap<>(facetQueryFields.size()); for (String facetQueryField : facetQueryFields) { List<String> queries = new ArrayList<>(); int index = 0; for (Entry<String, String> bucket : sizeBucketsMap.entrySet()) { String sizeRange = bucket.getKey().trim(); Matcher matcher = SIZE_RANGE_PATTERN.matcher(sizeRange); if (!matcher.find()) { throw new SolrFacetConfigException( "Invalid size range. Example of a valid size range is: [0 TO 1024]"); } // build the facet query. e.g. {http://www.alfresco.org/model/content/1.0}content.size:[0 TO 1024] String facetQuery = facetQueryField + ':' + sizeRange; queries.add(facetQuery); // indexOf('[') => 1 String sizeRangeQuery = sizeRange.substring(1, sizeRange.length() - 1); sizeRangeQuery = sizeRangeQuery.replaceFirst("\\sTO\\s", "\"..\""); facetLabelMap.put(facetQuery, new FacetLabel(sizeRangeQuery, bucket.getValue(), index++)); } facetQueries.put(facetQueryField, queries); } this.facetQueriesMap = Collections.unmodifiableMap(facetQueries); }
Example 9
Source File: ActivityServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public void setFeedControl(FeedControl feedControl) { ParameterCheck.mandatory("feedControl", feedControl); String userId = getCurrentUser(); if (userId == null) { throw new AlfrescoRuntimeException("Current user " + userId + " is not permitted to set feed control"); } try { if (! existsFeedControl(feedControl)) { if (logger.isDebugEnabled()) { logger.debug("Inserting feed control for siteId: " + feedControl.getSiteId() + ",\n appToolId : " + feedControl.getAppToolId() + ",\n for user : " + userId); } //MNT-9104 If username contains uppercase letters the action of joining a site will not be displayed in "My activities" if (! userNamesAreCaseSensitive) { userId = userId.toLowerCase(); } feedControlDAO.insertFeedControl(new FeedControlEntity(userId, feedControl)); } } catch (SQLException e) { AlfrescoRuntimeException are = new AlfrescoRuntimeException("Failed to set feed control: " + e, e); logger.error(are); throw are; } }
Example 10
Source File: AbstractAclCrudDAOImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public Ace getAce(Permission permission, Authority authority, ACEType type, AccessStatus accessStatus) { ParameterCheck.mandatory("permission", permission); ParameterCheck.mandatory("authority", authority); ParameterCheck.mandatory("type", type); ParameterCheck.mandatory("accessStatus", accessStatus); return getAceEntity(permission.getId(), authority.getId(), ((accessStatus == AccessStatus.ALLOWED) ? true : false), type); }
Example 11
Source File: ThumbnailParentAssociationDetails.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Constructor. All parameters must be specified. * * @param parent the parent node reference * @param assocType the child association type * @param assocName the child association name */ public ThumbnailParentAssociationDetails(NodeRef parent, QName assocType, QName assocName) { // Make sure all the details of the parent are provided ParameterCheck.mandatory("parent", parent); ParameterCheck.mandatory("assocType", assocType); ParameterCheck.mandatory("assocName", assocName); // Set the values this.parent = parent; this.assocType = assocType; this.assocName = assocName; }
Example 12
Source File: EmailServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * @param nodeRef Target node * @return Handler that can process message addressed to specific node (target node). * @throws EmailMessageException is thrown if a suitable message handler isn't found. */ private EmailMessageHandler getMessageHandler(NodeRef nodeRef) { ParameterCheck.mandatory("nodeRef", nodeRef); QName nodeTypeQName = nodeService.getType(nodeRef); String prefixedNodeTypeStr = nodeTypeQName.toPrefixString(namespaceService); EmailMessageHandler handler = emailMessageHandlerMap.get(prefixedNodeTypeStr); if( handler == null) { if(logger.isDebugEnabled()) { logger.debug("did not find a handler for type:" + prefixedNodeTypeStr); } // not a direct match on type // need to check the super-types (if any) of the target node TypeDefinition typeDef = dictionaryService.getType(nodeTypeQName); while(typeDef != null) { QName parentName = typeDef.getParentName(); if(parentName != null) { String prefixedSubTypeStr = parentName.toPrefixString(namespaceService); handler = emailMessageHandlerMap.get(prefixedSubTypeStr); if(handler != null) { if(logger.isDebugEnabled()) { logger.debug("found a handler for a subtype:" + prefixedSubTypeStr); } return handler; } } typeDef = dictionaryService.getType(parentName); } } if (handler == null) { throw new EmailMessageException(ERR_HANDLER_NOT_FOUND, prefixedNodeTypeStr); } return handler; }
Example 13
Source File: ClasspathScriptLocation.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Constructor * * @param location the classpath location */ public ClasspathScriptLocation(String location) { ParameterCheck.mandatory("Location", location); this.location = location; }
Example 14
Source File: RuleServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@Override @SuppressWarnings("unchecked") public void addRulePendingExecution(NodeRef actionableNodeRef, NodeRef actionedUponNodeRef, Rule rule, boolean executeAtEnd) { ParameterCheck.mandatory("actionableNodeRef", actionableNodeRef); ParameterCheck.mandatory("actionedUponNodeRef", actionedUponNodeRef); // First check to see if the node has been disabled if (this.isEnabled() == true && this.rulesEnabled(this.getOwningNodeRef(rule)) && this.disabledRules.contains(rule) == false) { PendingRuleData pendingRuleData = new PendingRuleData(actionableNodeRef, actionedUponNodeRef, rule, executeAtEnd); pendingRuleData.setRunAsUser(AuthenticationUtil.getRunAsUser()); List<PendingRuleData> pendingRules = (List<PendingRuleData>) AlfrescoTransactionSupport.getResource(KEY_RULES_PENDING); if (pendingRules == null) { // bind pending rules to the current transaction pendingRules = new ArrayList<PendingRuleData>(); AlfrescoTransactionSupport.bindResource(KEY_RULES_PENDING, pendingRules); // bind the rule transaction listener AlfrescoTransactionSupport.bindListener(this.ruleTransactionListener); if (logger.isDebugEnabled() == true) { logger.debug("Rule '" + rule.getTitle() + "' has been added pending execution to action upon node '" + actionedUponNodeRef.getId() + "'"); } } // Prevent the same rule being executed more than once in the same transaction if (pendingRules.contains(pendingRuleData) == false) { if ((AuthenticationUtil.isRunAsUserTheSystemUser()) && (rule.getAction() instanceof ActionImpl)) { ((ActionImpl)rule.getAction()).setRunAsUser(AuthenticationUtil.SYSTEM_USER_NAME); } pendingRules.add(pendingRuleData); } } else { if (logger.isDebugEnabled() == true) { logger.debug("The rule '" + rule.getTitle() + "' or the node '" + this.getOwningNodeRef(rule).getId() + "' has been disabled."); } } }
Example 15
Source File: NamedObjectRegistry.java From alfresco-core with GNU Lesser General Public License v3.0 | 4 votes |
/** * Register a named object instance. * * @param name the name of the object * @param object the instance to register, which correspond to the type */ public void register(String name, T object) { ParameterCheck.mandatoryString("name", name); ParameterCheck.mandatory("object", object); if (!storageType.isAssignableFrom(object.getClass())) { throw new IllegalArgumentException( "This NameObjectRegistry only accepts objects of type " + storageType); } writeLock.lock(); try { if (storageType == null) { throw new IllegalStateException( "The registry has not been configured (setStorageType not yet called yet)"); } if (namePattern != null) { if (!namePattern.matcher(name).matches()) { throw new IllegalArgumentException( "Object name '" + name + "' does not match required pattern: " + namePattern); } } T prevObject = objects.put(name, object); if (prevObject != null && prevObject != object) { logger.warn( "Overwriting name object in registry: \n" + " Previous: " + prevObject + "\n" + " New: " + object); } } finally { writeLock.unlock(); } }
Example 16
Source File: ThumbnailServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * @see org.alfresco.service.cmr.thumbnail.ThumbnailService#createThumbnail(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName, java.lang.String, org.alfresco.service.cmr.repository.TransformationOptions, java.lang.String, org.alfresco.service.cmr.thumbnail.ThumbnailParentAssociationDetails) */ public NodeRef createThumbnail(final NodeRef node, final QName contentProperty, final String mimetype, final TransformationOptions transformationOptions, final String thumbnailName, final ThumbnailParentAssociationDetails assocDetails) { // Parameter check ParameterCheck.mandatory("node", node); ParameterCheck.mandatory("contentProperty", contentProperty); ParameterCheck.mandatoryString("mimetype", mimetype); ParameterCheck.mandatory("transformationOptions", transformationOptions); if (logger.isDebugEnabled() == true) { logger.debug("Creating thumbnail (node=" + node.toString() + "; contentProperty=" + contentProperty.toString() + "; mimetype=" + mimetype); } if (thumbnailName != null) { NodeRef existingThumbnail = getThumbnailByName(node, contentProperty, thumbnailName); if (existingThumbnail != null) { if (logger.isDebugEnabled() == true) { logger.debug("Creating thumbnail: There is already a thumbnail with the name '" + thumbnailName + "' (node=" + node.toString() + "; contentProperty=" + contentProperty.toString() + "; mimetype=" + mimetype); } // Return the thumbnail that has already been created return existingThumbnail; } } RetryingTransactionHelper txnHelper = transactionService.getRetryingTransactionHelper(); txnHelper.setForceWritable(true); boolean requiresNew = false; if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_READ_WRITE) { //We can be in a read-only transaction, so force a new transaction requiresNew = true; } return txnHelper.doInTransaction(new RetryingTransactionCallback<NodeRef>() { @Override public NodeRef execute() throws Throwable { return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<NodeRef>() { public NodeRef doWork() throws Exception { return createThumbnailNode( node, contentProperty, mimetype, transformationOptions, thumbnailName, assocDetails); } }, AuthenticationUtil.getSystemUserName()); } }, false, requiresNew); }
Example 17
Source File: BehaviourFilterImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@Override @Extend(traitAPI = BehaviourFilterTrait.class, extensionAPI = BehaviourFilterExtension.class) public boolean isEnabled(NodeRef nodeRef, QName className) { ParameterCheck.mandatory("nodeRef", nodeRef); ParameterCheck.mandatory("className", className); // Check the class (includes global) and instance, first if (!isEnabled(className) || !isEnabled(nodeRef)) { return false; } if (!TransactionalResourceHelper.isResourcePresent(KEY_INSTANCE_CLASS_FILTERS)) { // Nothing was disabled return true; } nodeRef = tenantService.getName(nodeRef); Map<NodeRef, Map<QName, MutableInt>> instanceClassFilters = TransactionalResourceHelper.getMap(KEY_INSTANCE_CLASS_FILTERS); Map<QName, MutableInt> classFilters = instanceClassFilters.get(nodeRef); if (classFilters == null) { // Instance classes were not disabled return true; } for (QName classCheck : classFilters.keySet()) { // Ignore if it is not part of the hierarchy we are requesting if (!dictionaryService.isSubClass(className, classCheck)) { continue; } MutableInt filter = classFilters.get(classCheck); if (filter != null && filter.intValue() > 0) { // Class was disabled return false; } } return true; }
Example 18
Source File: People.java From alfresco-repository with GNU Lesser General Public License v3.0 | 2 votes |
/** * Return true if the specified user is an Administrator authority. * * @param person to test * * @return true if an admin, false otherwise */ public boolean isAdmin(ScriptNode person) { ParameterCheck.mandatory("Person", person); return this.authorityService.isAdminAuthority((String)person.getProperties().get(ContentModel.PROP_USERNAME)); }
Example 19
Source File: People.java From alfresco-repository with GNU Lesser General Public License v3.0 | 2 votes |
/** * Gets the members (people) of a group (including all sub-groups) * * @param group the group to retrieve members for * * @return list of nodes representing the group members */ public List<TemplateNode> getMembers(TemplateNode group) { ParameterCheck.mandatory("Group", group); return getContainedAuthorities(group, AuthorityType.USER, true); }
Example 20
Source File: ScriptNode.java From alfresco-repository with GNU Lesser General Public License v3.0 | 2 votes |
/** * Process a FreeMarker Template against the current node. * * @param template Node of the template to execute * @param args Scriptable object (generally an associative array) containing the name/value pairs of * arguments to be passed to the template * * @return output of the template execution */ public String processTemplate(ScriptNode template, Object args) { ParameterCheck.mandatory("Template Node", template); return processTemplate(template.getContent(), null, (ScriptableObject)args); }