Search in sources :

Example 16 with Pair

use of org.alfresco.util.Pair in project records-management by Alfresco.

the class RecordServiceImpl method createRecord.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.record.RecordService#createRecord(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef, boolean)
 */
@Override
public void createRecord(final NodeRef filePlan, final NodeRef nodeRef, final boolean isLinked) {
    // filePlan can be null. In this case the default RM site will be used.
    ParameterCheck.mandatory("nodeRef", nodeRef);
    ParameterCheck.mandatory("isLinked", isLinked);
    recordCreationSanityCheckOnNode(nodeRef);
    final NodeRef checkedFilePlan = recordCreationSanityCheckOnFilePlan(filePlan);
    invokeBeforeRecordDeclaration(nodeRef);
    // do the work of creating the record as the system user
    AuthenticationUtil.runAsSystem(new RunAsWork<Void>() {

        @Override
        public Void doWork() {
            if (!nodeService.hasAspect(nodeRef, ASPECT_RECORD)) {
                // disable delete rules
                ruleService.disableRuleType("outbound");
                try {
                    // get the new record container for the file plan
                    NodeRef newRecordContainer = filePlanService.getUnfiledContainer(checkedFilePlan);
                    if (newRecordContainer == null) {
                        throw new AlfrescoRuntimeException("Unable to create record, because new record container could not be found.");
                    }
                    // get the documents readers and writers
                    Pair<Set<String>, Set<String>> readersAndWriters = extendedPermissionService.getReadersAndWriters(nodeRef);
                    // get the current owner
                    String owner = ownableService.getOwner(nodeRef);
                    // get the documents primary parent assoc
                    ChildAssociationRef parentAssoc = nodeService.getPrimaryParent(nodeRef);
                    // get the latest version record, if there is one
                    NodeRef latestVersionRecord = getLatestVersionRecord(nodeRef);
                    behaviourFilter.disableBehaviour();
                    try {
                        // move the document into the file plan
                        nodeService.moveNode(nodeRef, newRecordContainer, ContentModel.ASSOC_CONTAINS, parentAssoc.getQName());
                    } finally {
                        behaviourFilter.enableBehaviour();
                    }
                    // save the information about the originating details
                    Map<QName, Serializable> aspectProperties = new HashMap<QName, Serializable>(3);
                    aspectProperties.put(PROP_RECORD_ORIGINATING_LOCATION, parentAssoc.getParentRef());
                    aspectProperties.put(PROP_RECORD_ORIGINATING_USER_ID, owner);
                    aspectProperties.put(PROP_RECORD_ORIGINATING_CREATION_DATE, new Date());
                    nodeService.addAspect(nodeRef, ASPECT_RECORD_ORIGINATING_DETAILS, aspectProperties);
                    // make the document a record
                    makeRecord(nodeRef);
                    generateRecordIdentifier(nodeService, identifierService, nodeRef);
                    if (latestVersionRecord != null) {
                        // indicate that this is the 'final' record version
                        PropertyMap versionRecordProps = new PropertyMap(2);
                        versionRecordProps.put(RecordableVersionModel.PROP_VERSION_LABEL, I18NUtil.getMessage(FINAL_VERSION));
                        versionRecordProps.put(RecordableVersionModel.PROP_VERSION_DESCRIPTION, I18NUtil.getMessage(FINAL_DESCRIPTION));
                        nodeService.addAspect(nodeRef, RecordableVersionModel.ASPECT_VERSION_RECORD, versionRecordProps);
                        // link to previous version
                        relationshipService.addRelationship(CUSTOM_REF_VERSIONS.getLocalName(), nodeRef, latestVersionRecord);
                    }
                    if (isLinked) {
                        // turn off rules
                        ruleService.disableRules();
                        try {
                            // maintain the original primary location
                            nodeService.addChild(parentAssoc.getParentRef(), nodeRef, parentAssoc.getTypeQName(), parentAssoc.getQName());
                            // set the extended security
                            extendedSecurityService.set(nodeRef, readersAndWriters);
                        } finally {
                            ruleService.enableRules();
                        }
                    }
                } finally {
                    ruleService.enableRuleType("outbound");
                }
            }
            return null;
        }
    });
    invokeOnRecordDeclaration(nodeRef);
}
Also used : Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) Date(java.util.Date) NodeRef(org.alfresco.service.cmr.repository.NodeRef) PropertyMap(org.alfresco.util.PropertyMap) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) Map(java.util.Map) PropertyMap(org.alfresco.util.PropertyMap) HashMap(java.util.HashMap) Pair(org.alfresco.util.Pair)

Example 17 with Pair

use of org.alfresco.util.Pair in project records-management by Alfresco.

the class RecordsManagementAuditEntry method initChangedProperties.

/**
 * Initialises the map of changed values given the before and after properties
 */
private void initChangedProperties() {
    if (this.beforeProperties != null && this.afterProperties != null) {
        this.changedProperties = new HashMap<QName, Pair<Serializable, Serializable>>(this.beforeProperties.size() + this.afterProperties.size());
        // add all the properties present before the audited action
        for (QName valuePropName : this.beforeProperties.keySet()) {
            Pair<Serializable, Serializable> values = new Pair<Serializable, Serializable>(this.beforeProperties.get(valuePropName), this.afterProperties.get(valuePropName));
            this.changedProperties.put(valuePropName, values);
        }
        // have not already been added
        for (QName valuePropName : this.afterProperties.keySet()) {
            if (!this.beforeProperties.containsKey(valuePropName)) {
                Pair<Serializable, Serializable> values = new Pair<Serializable, Serializable>(null, this.afterProperties.get(valuePropName));
                this.changedProperties.put(valuePropName, values);
            }
        }
    }
}
Also used : Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) Pair(org.alfresco.util.Pair)

Example 18 with Pair

use of org.alfresco.util.Pair in project records-management by Alfresco.

the class RecordsManagementSearchServiceImpl method search.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.search.RecordsManagementSearchService#search(java.lang.String, java.lang.String, org.alfresco.module.org_alfresco_module_rm.search.RecordsManagementSearchParameters)
 */
@Override
public List<Pair<NodeRef, NodeRef>> search(String siteId, String query, RecordsManagementSearchParameters rmSearchParameters) {
    // build the full RM query
    StringBuilder fullQuery = new StringBuilder(1024);
    fullQuery.append("PATH:\"").append(SITES_SPACE_QNAME_PATH).append("cm:").append(ISO9075.encode(siteId)).append("/cm:documentLibrary//*\"").append(" AND (").append(buildQueryString(query, rmSearchParameters)).append(")");
    // create the search parameters
    SearchParameters searchParameters = new SearchParameters();
    searchParameters.setQuery(fullQuery.toString());
    searchParameters.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO);
    searchParameters.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
    searchParameters.setMaxItems(rmSearchParameters.getMaxItems());
    searchParameters.setNamespace(RecordsManagementModel.RM_URI);
    // set sort
    for (SortItem entry : rmSearchParameters.getSortOrder()) {
        searchParameters.addSort(entry.property.toPrefixString(namespaceService), entry.assc);
    }
    // set templates
    for (Entry<String, String> entry : rmSearchParameters.getTemplates().entrySet()) {
        searchParameters.addQueryTemplate(entry.getKey(), entry.getValue());
    }
    // execute query
    ResultSet resultSet = searchService.query(searchParameters);
    // process results
    List<Pair<NodeRef, NodeRef>> result = new ArrayList<Pair<NodeRef, NodeRef>>(resultSet.length());
    for (ChildAssociationRef childAssoc : resultSet.getChildAssocRefs()) {
        result.add(new Pair<NodeRef, NodeRef>(childAssoc.getParentRef(), childAssoc.getChildRef()));
    }
    // return results
    return result;
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ResultSet(org.alfresco.service.cmr.search.ResultSet) ArrayList(java.util.ArrayList) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) Pair(org.alfresco.util.Pair)

Example 19 with Pair

use of org.alfresco.util.Pair in project records-management by Alfresco.

the class ExtendedSecurityServiceImpl method findIPRGroup.

/**
 * Given a group name prefix and the authorities, finds the exact match existing group.
 * <p>
 * If the group does not exist then the group returned is null and the index shows the next available
 * group index for creation.
 *
 * @param groupPrefix             group name prefix
 * @param authorities             authorities
 * @return Pair<String, Integer>  where first is the name of the found group, null if none found and second
 *                                if the next available create index
 */
private Pair<String, Integer> findIPRGroup(String groupPrefix, Set<String> authorities) {
    String iprGroup = null;
    int nextGroupIndex = 0;
    boolean hasMoreItems = true;
    int pageCount = 0;
    // determine the short name prefix
    String groupShortNamePrefix = getIPRGroupPrefixShortName(groupPrefix, authorities);
    // iterate over the authorities to find a match
    while (hasMoreItems == true) {
        // get matching authorities
        PagingResults<String> results = authorityService.getAuthorities(AuthorityType.GROUP, RMAuthority.ZONE_APP_RM, groupShortNamePrefix, false, false, new PagingRequest(MAX_ITEMS * pageCount, MAX_ITEMS));
        // record the total count
        nextGroupIndex = nextGroupIndex + results.getPage().size();
        // see if any of the matching groups exactly match
        for (String group : results.getPage()) {
            // if exists and matches we have found our group
            if (isIPRGroupTrueMatch(group, authorities)) {
                iprGroup = group;
                break;
            }
        }
        // determine if there are any more pages to inspect
        hasMoreItems = results.hasMoreItems();
        pageCount++;
    }
    return new Pair<String, Integer>(iprGroup, nextGroupIndex);
}
Also used : PagingRequest(org.alfresco.query.PagingRequest) Pair(org.alfresco.util.Pair)

Example 20 with Pair

use of org.alfresco.util.Pair in project SearchServices by Alfresco.

the class Solr4QueryParser method getRangeQuery.

/**
 * @param field
 * @param part1
 * @param part2
 * @param includeLower
 * @param includeUpper
 * @param analysisMode
 * @param luceneFunction
 * @return the query
 * @exception ParseException
 *                throw in overridden method to disallow
 */
public Query getRangeQuery(String field, String part1, String part2, boolean includeLower, boolean includeUpper, AnalysisMode analysisMode, LuceneFunction luceneFunction) throws ParseException {
    if (field.equals(FIELD_PATH)) {
        throw new UnsupportedOperationException("Range Queries are not support for " + FIELD_PATH);
    } else if (field.equals(FIELD_PATHWITHREPEATS)) {
        throw new UnsupportedOperationException("Range Queries are not support for " + FIELD_PATHWITHREPEATS);
    } else if (field.equals(FIELD_TEXT)) {
        Set<String> text = searchParameters.getTextAttributes();
        if ((text == null) || (text.size() == 0)) {
            Query query = getRangeQuery(PROPERTY_FIELD_PREFIX + ContentModel.PROP_CONTENT.toString(), part1, part2, includeLower, includeUpper, analysisMode, luceneFunction);
            if (query == null) {
                return createNoMatchQuery();
            }
            return query;
        } else {
            BooleanQuery.Builder query = new BooleanQuery.Builder();
            for (String fieldName : text) {
                Query part = getRangeQuery(fieldName, part1, part2, includeLower, includeUpper, analysisMode, luceneFunction);
                if (part != null) {
                    query.add(part, Occur.SHOULD);
                } else {
                    query.add(createNoMatchQuery(), Occur.SHOULD);
                }
            }
            return query.build();
        }
    } else if (field.equals(FIELD_CASCADETX)) {
        SchemaField sf = schema.getField(FIELD_CASCADETX);
        if (sf != null) {
            String start = null;
            try {
                analyzeMultitermTerm(FIELD_CASCADETX, part1);
                start = part1;
            } catch (Exception e) {
            }
            String end = null;
            try {
                analyzeMultitermTerm(FIELD_CASCADETX, part2);
                end = part2;
            } catch (Exception e) {
            }
            return sf.getType().getRangeQuery(null, sf, start, end, includeLower, includeUpper);
        } else {
            throw new UnsupportedOperationException();
        }
    }
    // FIELD_TYPE uses the default
    if (isPropertyField(field)) {
        Pair<String, String> fieldNameAndEnding = QueryParserUtils.extractFieldNameAndEnding(field);
        String expandedFieldName = null;
        PropertyDefinition propertyDef = QueryParserUtils.matchPropertyDefinition(searchParameters.getNamespace(), namespacePrefixResolver, dictionaryService, fieldNameAndEnding.getFirst());
        IndexTokenisationMode tokenisationMode = IndexTokenisationMode.TRUE;
        if (propertyDef != null) {
            tokenisationMode = propertyDef.getIndexTokenisationMode();
            if (tokenisationMode == null) {
                tokenisationMode = IndexTokenisationMode.TRUE;
            }
        } else {
            expandedFieldName = expandAttributeFieldName(field);
        }
        if (propertyDef != null) {
            // LOWER AND UPPER
            if (luceneFunction != LuceneFunction.FIELD) {
                if (luceneFunction == LuceneFunction.LOWER) {
                    if ((false == part1.toLowerCase().equals(part1)) || (false == part2.toLowerCase().equals(part2))) {
                        return createNoMatchQuery();
                    }
                }
                if (luceneFunction == LuceneFunction.UPPER) {
                    if ((false == part1.toUpperCase().equals(part1)) || (false == part2.toUpperCase().equals(part2))) {
                        return createNoMatchQuery();
                    }
                }
                if (propertyDef.getDataType().getName().equals(DataTypeDefinition.TEXT)) {
                    BooleanQuery.Builder booleanQuery = new BooleanQuery.Builder();
                    List<Locale> locales = searchParameters.getLocales();
                    List<Locale> expandedLocales = new ArrayList<Locale>();
                    for (Locale locale : (((locales == null) || (locales.size() == 0)) ? Collections.singletonList(I18NUtil.getLocale()) : locales)) {
                        expandedLocales.addAll(MLAnalysisMode.getLocales(mlAnalysisMode, locale, false));
                    }
                    for (Locale locale : (((expandedLocales == null) || (expandedLocales.size() == 0)) ? Collections.singletonList(I18NUtil.getLocale()) : expandedLocales)) {
                        addLocaleSpecificUntokenisedTextRangeFunction(expandedFieldName, propertyDef, part1, part2, includeLower, includeUpper, luceneFunction, booleanQuery, locale, tokenisationMode);
                    }
                    return booleanQuery.build();
                } else {
                    throw new UnsupportedOperationException("Lucene Function");
                }
            }
            if (propertyDef.getDataType().getName().equals(DataTypeDefinition.MLTEXT)) {
                return buildTextMLTextOrContentRange(field, part1, part2, includeLower, includeUpper, analysisMode, expandedFieldName, propertyDef, tokenisationMode);
            } else if (propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT)) {
                String solrField = null;
                switch(fieldNameAndEnding.getSecond()) {
                    case FIELD_SIZE_SUFFIX:
                        solrField = AlfrescoSolrDataModel.getInstance().getQueryableFields(propertyDef.getName(), ContentFieldType.SIZE, FieldUse.ID).getFields().get(0).getField();
                        break;
                    case FIELD_MIMETYPE_SUFFIX:
                        solrField = AlfrescoSolrDataModel.getInstance().getQueryableFields(propertyDef.getName(), ContentFieldType.MIMETYPE, FieldUse.ID).getFields().get(0).getField();
                        break;
                    case FIELD_ENCODING_SUFFIX:
                        solrField = AlfrescoSolrDataModel.getInstance().getQueryableFields(propertyDef.getName(), ContentFieldType.ENCODING, FieldUse.ID).getFields().get(0).getField();
                        break;
                    case FIELD_LOCALE_SUFFIX:
                        solrField = AlfrescoSolrDataModel.getInstance().getQueryableFields(propertyDef.getName(), ContentFieldType.LOCALE, FieldUse.ID).getFields().get(0).getField();
                        break;
                }
                if (solrField != null) {
                    String start = null;
                    try {
                        analyzeMultitermTerm(solrField, part1);
                        start = part1;
                    } catch (Exception e) {
                    }
                    String end = null;
                    try {
                        analyzeMultitermTerm(solrField, part2);
                        end = part2;
                    } catch (Exception e) {
                    }
                    SchemaField sf = schema.getField(solrField);
                    return sf.getType().getRangeQuery(null, sf, start, end, includeLower, includeUpper);
                } else {
                    return buildTextMLTextOrContentRange(field, part1, part2, includeLower, includeUpper, analysisMode, expandedFieldName, propertyDef, tokenisationMode);
                }
            } else if (propertyDef.getDataType().getName().equals(DataTypeDefinition.TEXT)) {
                return buildTextMLTextOrContentRange(field, part1, part2, includeLower, includeUpper, analysisMode, expandedFieldName, propertyDef, tokenisationMode);
            } else if (propertyDef.getDataType().getName().equals(DataTypeDefinition.DATETIME) || propertyDef.getDataType().getName().equals(DataTypeDefinition.DATE)) {
                Pair<Date, Integer> dateAndResolution1 = parseDateString(part1);
                Pair<Date, Integer> dateAndResolution2 = parseDateString(part2);
                BooleanQuery.Builder bQuery = new BooleanQuery.Builder();
                IndexedField indexedField = AlfrescoSolrDataModel.getInstance().getQueryableFields(propertyDef.getName(), null, FieldUse.ID);
                for (FieldInstance instance : indexedField.getFields()) {
                    String start = dateAndResolution1 == null ? part1 : (includeLower ? getDateStart(dateAndResolution1) : getDateEnd(dateAndResolution1));
                    String end = dateAndResolution2 == null ? part2 : (includeUpper ? getDateEnd(dateAndResolution2) : getDateStart(dateAndResolution2));
                    if (start.equals("*")) {
                        start = null;
                    }
                    if (end.equals("*")) {
                        end = null;
                    }
                    SchemaField sf = schema.getField(instance.getField());
                    Query query = sf.getType().getRangeQuery(null, sf, start, end, includeLower, includeUpper);
                    if (query != null) {
                        bQuery.add(query, Occur.SHOULD);
                    }
                }
                return bQuery.build();
            } else {
                String solrField = AlfrescoSolrDataModel.getInstance().getQueryableFields(propertyDef.getName(), null, FieldUse.ID).getFields().get(0).getField();
                String start = null;
                try {
                    analyzeMultitermTerm(solrField, part1);
                    start = part1;
                } catch (Exception e) {
                }
                String end = null;
                try {
                    analyzeMultitermTerm(solrField, part2);
                    end = part2;
                } catch (Exception e) {
                }
                SchemaField sf = schema.getField(solrField);
                return sf.getType().getRangeQuery(null, sf, start, end, includeLower, includeUpper);
            }
        } else {
            throw new UnsupportedOperationException();
        }
    } else if (field.equals(FIELD_ALL)) {
        Set<String> all = searchParameters.getAllAttributes();
        if ((all == null) || (all.size() == 0)) {
            Collection<QName> contentAttributes = dictionaryService.getAllProperties(null);
            BooleanQuery.Builder query = new BooleanQuery.Builder();
            for (QName qname : contentAttributes) {
                Query part = getRangeQuery(PROPERTY_FIELD_PREFIX + qname.toString(), part1, part2, includeLower, includeUpper, analysisMode, luceneFunction);
                query.add(part, Occur.SHOULD);
            }
            return query.build();
        } else {
            BooleanQuery.Builder query = new BooleanQuery.Builder();
            for (String fieldName : all) {
                Query part = getRangeQuery(fieldName, part1, part2, includeLower, includeUpper, analysisMode, luceneFunction);
                query.add(part, Occur.SHOULD);
            }
            return query.build();
        }
    } else // FIELD_EXISTS uses the default
    if (QueryParserUtils.matchDataTypeDefinition(searchParameters.getNamespace(), namespacePrefixResolver, dictionaryService, field) != null) {
        Collection<QName> contentAttributes = dictionaryService.getAllProperties(QueryParserUtils.matchDataTypeDefinition(searchParameters.getNamespace(), namespacePrefixResolver, dictionaryService, field).getName());
        BooleanQuery.Builder query = new BooleanQuery.Builder();
        for (QName qname : contentAttributes) {
            Query part = getRangeQuery(PROPERTY_FIELD_PREFIX + qname.toString(), part1, part2, includeLower, includeUpper, analysisMode, luceneFunction);
            query.add(part, Occur.SHOULD);
        }
        return query.build();
    }
    // FIELD_FTSSTATUS uses the default
    if (field.equals(FIELD_TAG)) {
        throw new UnsupportedOperationException("Range Queries are not support for " + FIELD_TAG);
    } else {
        // None property - leave alone
        throw new UnsupportedOperationException();
    }
}
Also used : Locale(java.util.Locale) BooleanQuery(org.apache.lucene.search.BooleanQuery) Set(java.util.Set) OrderedHashSet(org.antlr.misc.OrderedHashSet) HashSet(java.util.HashSet) Query(org.apache.lucene.search.Query) RegexpQuery(org.apache.lucene.search.RegexpQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) ConstantScoreQuery(org.apache.lucene.search.ConstantScoreQuery) SpanNearQuery(org.apache.lucene.search.spans.SpanNearQuery) SpanOrQuery(org.apache.lucene.search.spans.SpanOrQuery) MultiTermQuery(org.apache.lucene.search.MultiTermQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanQuery(org.apache.lucene.search.spans.SpanQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) IndexedField(org.alfresco.solr.AlfrescoSolrDataModel.IndexedField) QName(org.alfresco.service.namespace.QName) Builder(org.apache.lucene.search.BooleanQuery.Builder) ArrayList(java.util.ArrayList) Builder(org.apache.lucene.search.BooleanQuery.Builder) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) IndexTokenisationMode(org.alfresco.repo.dictionary.IndexTokenisationMode) SAXPathException(org.jaxen.saxpath.SAXPathException) ParseException(org.apache.lucene.queryparser.classic.ParseException) FTSQueryException(org.alfresco.repo.search.impl.parsers.FTSQueryException) IOException(java.io.IOException) SchemaField(org.apache.solr.schema.SchemaField) Collection(java.util.Collection) FieldInstance(org.alfresco.solr.AlfrescoSolrDataModel.FieldInstance) Pair(org.alfresco.util.Pair)

Aggregations

Pair (org.alfresco.util.Pair)61 ArrayList (java.util.ArrayList)34 NodeRef (org.alfresco.service.cmr.repository.NodeRef)23 QName (org.alfresco.service.namespace.QName)22 HashMap (java.util.HashMap)16 PagingRequest (org.alfresco.query.PagingRequest)13 Paging (org.alfresco.rest.framework.resource.parameters.Paging)12 List (java.util.List)11 Serializable (java.io.Serializable)10 HashSet (java.util.HashSet)9 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)9 Set (java.util.Set)8 Map (java.util.Map)7 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)7 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)7 AbstractList (java.util.AbstractList)6 Arrays (java.util.Arrays)6 Collections (java.util.Collections)6 PagingResults (org.alfresco.query.PagingResults)6 Node (org.alfresco.rest.api.model.Node)6