Search in sources :

Example 1 with Pair

use of org.alfresco.util.Pair in project alfresco-remote-api by Alfresco.

the class NodeVersionsApiTest method uploadTextFileVersions.

/**
 * This test helper method uses "overwrite=true" to create one or more new versions, including the initial create if needed.
 *
 * If the file does not already exist (currentVersionLabel should be null) and majorVersionIn is also null
 * then the first version is created as MAJOR (1.0) and subsequent versions are created as MINOR.
 *
 * @param userId
 * @param parentFolderNodeId - parent folder
 * @param fileName - file name
 * @param cnt - number of new versions (>= 1)
 * @param textContentPrefix - prefix for text content
 * @param currentVersionCounter - overall version counter, used as a suffix in text content and version comment
 * @param majorVersionIn - if null then false, if true then create MAJOR versions else if false create MINOR versions
 * @param currentVersionLabel - the current version label (if file already exists)
 * @return
 * @throws Exception
 */
private Pair<String, String> uploadTextFileVersions(String userId, String parentFolderNodeId, String fileName, int cnt, String textContentPrefix, int currentVersionCounter, final Boolean majorVersionIn, String currentVersionLabel) throws Exception {
    Map<String, String> params = new HashMap<>();
    params.put(Nodes.PARAM_OVERWRITE, "true");
    if (majorVersionIn != null) {
        params.put(Nodes.PARAM_VERSION_MAJOR, majorVersionIn.toString());
    }
    String docId = null;
    for (int i = 1; i <= cnt; i++) {
        boolean expectedMajorVersion = (majorVersionIn != null ? majorVersionIn : false);
        if (currentVersionLabel == null) {
            currentVersionLabel = "0.0";
            // special case - 1st version is major (if not specified otherwise)
            if (majorVersionIn == null) {
                expectedMajorVersion = true;
            }
        }
        String[] parts = currentVersionLabel.split("\\.");
        int majorVer = new Integer(parts[0]).intValue();
        int minorVer = new Integer(parts[1]).intValue();
        if (expectedMajorVersion) {
            majorVer++;
            minorVer = 0;
        } else {
            minorVer++;
        }
        currentVersionLabel = majorVer + "." + minorVer;
        currentVersionCounter++;
        params.put("comment", "my version " + currentVersionCounter);
        String textContent = textContentPrefix + currentVersionCounter;
        // uses upload with overwrite here ...
        Document documentResp = createTextFile(parentFolderNodeId, fileName, textContent, "UTF-8", params);
        docId = documentResp.getId();
        assertTrue(documentResp.getAspectNames().contains("cm:versionable"));
        assertNotNull(documentResp.getProperties());
        assertEquals(currentVersionLabel, documentResp.getProperties().get("cm:versionLabel"));
        // double-check - get version node info
        HttpResponse response = getSingle(getNodeVersionsUrl(docId), currentVersionLabel, null, 200);
        Node nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
        assertEquals(currentVersionLabel, nodeResp.getProperties().get("cm:versionLabel"));
        assertEquals((expectedMajorVersion ? "MAJOR" : "MINOR"), nodeResp.getProperties().get("cm:versionType"));
    }
    return new Pair<String, String>(currentVersionLabel, docId);
}
Also used : HashMap(java.util.HashMap) Node(org.alfresco.rest.api.tests.client.data.Node) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) Document(org.alfresco.rest.api.tests.client.data.Document) Pair(org.alfresco.util.Pair)

Example 2 with Pair

use of org.alfresco.util.Pair in project alfresco-remote-api by Alfresco.

the class TestDeclarativeSpreadsheetWebScriptGet method buildPropertiesForHeader.

@Override
protected List<Pair<QName, Boolean>> buildPropertiesForHeader(Object resource, String format, WebScriptRequest req) {
    List<Pair<QName, Boolean>> properties = new ArrayList<Pair<QName, Boolean>>(DeclarativeSpreadsheetWebScriptTest.COLUMNS.length);
    boolean required = true;
    for (QName qname : DeclarativeSpreadsheetWebScriptTest.COLUMNS) {
        Pair<QName, Boolean> p = null;
        if (qname != null) {
            p = new Pair<QName, Boolean>(qname, required);
        } else {
            required = false;
        }
        properties.add(p);
    }
    return properties;
}
Also used : QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) Pair(org.alfresco.util.Pair)

Example 3 with Pair

use of org.alfresco.util.Pair in project alfresco-remote-api by Alfresco.

the class WebDAVLockServiceImplTest method testSessionDestroyed.

@Test
public void testSessionDestroyed() {
    List<Pair<String, NodeRef>> lockedNodes = new ArrayList<Pair<String, NodeRef>>(2);
    lockedNodes.add(new Pair<String, NodeRef>("some_user_name", nodeRef1));
    lockedNodes.add(new Pair<String, NodeRef>("another_user_name", nodeRef2));
    Mockito.when(sessionList.size()).thenReturn(2);
    Mockito.when(sessionList.iterator()).thenReturn(lockedNodes.iterator());
    Mockito.when(nodeService.exists(nodeRef1)).thenReturn(true);
    Mockito.when(nodeService.exists(nodeRef2)).thenReturn(true);
    Mockito.when(lockService.getLockStatus(nodeRef1)).thenReturn(LockStatus.LOCKED);
    Mockito.when(lockService.getLockStatus(nodeRef2)).thenReturn(LockStatus.LOCKED);
    // We're not going to do anything with nodeRef2
    NodeRef wcNodeRef2 = new NodeRef("workspace://SpacesStore/a6e3f82a-cfef-363d-9fca-3986a14180a0");
    Mockito.when(cociService.getWorkingCopy(nodeRef2)).thenReturn(wcNodeRef2);
    davLockService.sessionDestroyed();
    // nodeRef1 is unlocked
    Mockito.verify(lockService).unlock(nodeRef1);
    // nodeRef2 is not unlocked
    Mockito.verify(lockService, Mockito.never()).unlock(nodeRef2);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ArrayList(java.util.ArrayList) Pair(org.alfresco.util.Pair) Test(org.junit.Test)

Example 4 with Pair

use of org.alfresco.util.Pair in project alfresco-remote-api by Alfresco.

the class ResultMapper method getFacetBucketsForFacetFieldsAsFacets.

protected List<GenericFacetResponse> getFacetBucketsForFacetFieldsAsFacets(Map<String, List<Pair<String, Integer>>> facetFields, SearchQuery searchQuery) {
    if (facetFields != null && !facetFields.isEmpty()) {
        List<GenericFacetResponse> ffcs = new ArrayList<>(facetFields.size());
        for (Entry<String, List<Pair<String, Integer>>> facet : facetFields.entrySet()) {
            if (facet.getValue() != null && !facet.getValue().isEmpty()) {
                List<GenericBucket> buckets = new ArrayList<>(facet.getValue().size());
                for (Pair<String, Integer> buck : facet.getValue()) {
                    Object display = null;
                    String filterQuery = null;
                    if (searchQuery != null && searchQuery.getFacetFields() != null && searchQuery.getFacetFields().getFacets() != null && !searchQuery.getFacetFields().getFacets().isEmpty()) {
                        Optional<FacetField> found = searchQuery.getFacetFields().getFacets().stream().filter(queryable -> facet.getKey().equals(queryable.getLabel() != null ? queryable.getLabel() : queryable.getField())).findFirst();
                        if (found.isPresent()) {
                            display = propertyLookup.lookup(found.get().getField(), buck.getFirst());
                            String fq = found.get().toFilterQuery(buck.getFirst());
                            if (fq != null) {
                                filterQuery = fq;
                            }
                        }
                    }
                    GenericBucket bucket = new GenericBucket(buck.getFirst(), filterQuery, display, new HashSet<Metric>(Arrays.asList(new SimpleMetric(METRIC_TYPE.count, String.valueOf(buck.getSecond())))), null, null);
                    buckets.add(bucket);
                }
                ffcs.add(new GenericFacetResponse(FACET_TYPE.field, facet.getKey(), buckets));
            }
        }
        return ffcs;
    }
    return Collections.emptyList();
}
Also used : Arrays(java.util.Arrays) SearchContext(org.alfresco.rest.api.search.context.SearchContext) FacetQuery(org.alfresco.rest.api.search.model.FacetQuery) GenericBucket(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericBucket) LIVE_NODES(org.alfresco.rest.api.search.impl.StoreMapper.LIVE_NODES) Paging(org.alfresco.rest.framework.resource.parameters.Paging) FacetFormat(org.alfresco.service.cmr.search.FacetFormat) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) Params(org.alfresco.rest.framework.resource.parameters.Params) Node(org.alfresco.rest.api.model.Node) Map(java.util.Map) HISTORY(org.alfresco.rest.api.search.impl.StoreMapper.HISTORY) METRIC_TYPE(org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric.METRIC_TYPE) ResultSet(org.alfresco.service.cmr.search.ResultSet) TupleEntry(org.alfresco.rest.api.search.model.TupleEntry) DeletedNodes(org.alfresco.rest.api.DeletedNodes) FacetQueryContext(org.alfresco.rest.api.search.context.FacetQueryContext) Set(java.util.Set) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) List(java.util.List) Version2Model(org.alfresco.repo.version.Version2Model) IntervalSet(org.alfresco.service.cmr.search.IntervalSet) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) CollectionWithPagingInfo(org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo) SpellCheckContext(org.alfresco.rest.api.search.context.SpellCheckContext) Bucket(org.alfresco.rest.api.search.context.FacetFieldContext.Bucket) Entry(java.util.Map.Entry) Optional(java.util.Optional) Nodes(org.alfresco.rest.api.Nodes) LogFactory(org.apache.commons.logging.LogFactory) SearchSQLQuery(org.alfresco.rest.api.search.model.SearchSQLQuery) NodeVersionsRelation(org.alfresco.rest.api.nodes.NodeVersionsRelation) TupleList(org.alfresco.rest.api.search.model.TupleList) DELETED(org.alfresco.rest.api.search.impl.StoreMapper.DELETED) Metric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric) Interval(org.alfresco.service.cmr.search.Interval) SearchRequestContext(org.alfresco.rest.api.search.context.SearchRequestContext) SimpleMetric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.SimpleMetric) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Version(org.alfresco.service.cmr.version.Version) UserInfo(org.alfresco.rest.api.model.UserInfo) HashMap(java.util.HashMap) SearchEntry(org.alfresco.rest.api.search.model.SearchEntry) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) FacetField(org.alfresco.rest.api.search.model.FacetField) QName(org.alfresco.service.namespace.QName) RangeResultMapper(org.alfresco.repo.search.impl.solr.facet.facetsresponse.RangeResultMapper) PropertyLookupRegistry(org.alfresco.rest.api.lookups.PropertyLookupRegistry) ServiceRegistry(org.alfresco.service.ServiceRegistry) Pair(org.alfresco.util.Pair) FilteringResultSet(org.alfresco.repo.security.permissions.impl.acegi.FilteringResultSet) HighlightEntry(org.alfresco.rest.api.search.model.HighlightEntry) FacetFieldContext(org.alfresco.rest.api.search.context.FacetFieldContext) FACET_TYPE(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetResponse.FACET_TYPE) SearchQuery(org.alfresco.rest.api.search.model.SearchQuery) VERSIONS(org.alfresco.rest.api.search.impl.StoreMapper.VERSIONS) ResultSetRow(org.alfresco.service.cmr.search.ResultSetRow) Log(org.apache.commons.logging.Log) Collections(java.util.Collections) SolrJSONResultSet(org.alfresco.repo.search.impl.lucene.SolrJSONResultSet) SpellCheckResult(org.alfresco.service.cmr.search.SpellCheckResult) JSONArray(org.json.JSONArray) GenericFacetResponse(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetResponse) GenericFacetResponse(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericFacetResponse) ArrayList(java.util.ArrayList) GenericBucket(org.alfresco.repo.search.impl.solr.facet.facetsresponse.GenericBucket) FacetField(org.alfresco.rest.api.search.model.FacetField) SimpleMetric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.SimpleMetric) List(java.util.List) TupleList(org.alfresco.rest.api.search.model.TupleList) ArrayList(java.util.ArrayList) JSONObject(org.json.JSONObject) Metric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric) SimpleMetric(org.alfresco.repo.search.impl.solr.facet.facetsresponse.SimpleMetric)

Example 5 with Pair

use of org.alfresco.util.Pair in project alfresco-remote-api by Alfresco.

the class CustomModelsImpl method convertToM2Model.

/**
 * Converts the given {@code org.alfresco.rest.api.model.CustomModel}
 * object, a collection of {@code org.alfresco.rest.api.model.CustomType}
 * objects, a collection of
 * {@code org.alfresco.rest.api.model.CustomAspect} objects, and a collection of
 * {@code org.alfresco.rest.api.model.CustomModelConstraint} objects into a {@link M2Model} object
 *
 * @param customModel the custom model
 * @param types the custom types
 * @param aspects the custom aspects
 * @param constraints the custom constraints
 * @return {@link M2Model} object
 */
private M2Model convertToM2Model(CustomModel customModel, Collection<CustomType> types, Collection<CustomAspect> aspects, Collection<CustomModelConstraint> constraints) {
    validateBasicModelInput(customModel);
    Set<Pair<String, String>> namespacesToImport = new LinkedHashSet<>();
    final String namespacePrefix = customModel.getNamespacePrefix();
    final String namespaceURI = customModel.getNamespaceUri();
    // Construct the model name
    final String name = constructName(customModel.getName(), namespacePrefix);
    M2Model model = M2Model.createModel(name);
    model.createNamespace(namespaceURI, namespacePrefix);
    model.setDescription(customModel.getDescription());
    String author = customModel.getAuthor();
    if (author == null) {
        author = getCurrentUserFullName();
    }
    model.setAuthor(author);
    // Types
    if (types != null) {
        for (CustomType type : types) {
            validateName(type.getName(), TYPE_NAME_NULL_ERR);
            M2Type m2Type = model.createType(constructName(type.getName(), namespacePrefix));
            m2Type.setDescription(type.getDescription());
            m2Type.setTitle(type.getTitle());
            setParentName(m2Type, type.getParentName(), namespacesToImport, namespacePrefix);
            setM2Properties(m2Type, type.getProperties(), namespacePrefix, namespacesToImport);
        }
    }
    // Aspects
    if (aspects != null) {
        for (CustomAspect aspect : aspects) {
            validateName(aspect.getName(), ASPECT_NAME_NULL_ERR);
            M2Aspect m2Aspect = model.createAspect(constructName(aspect.getName(), namespacePrefix));
            m2Aspect.setDescription(aspect.getDescription());
            m2Aspect.setTitle(aspect.getTitle());
            setParentName(m2Aspect, aspect.getParentName(), namespacesToImport, namespacePrefix);
            setM2Properties(m2Aspect, aspect.getProperties(), namespacePrefix, namespacesToImport);
        }
    }
    // Constraints
    if (constraints != null) {
        for (CustomModelConstraint constraint : constraints) {
            validateName(constraint.getName(), CONSTRAINT_NAME_NULL_ERR);
            final String constraintName = constructName(constraint.getName(), namespacePrefix);
            M2Constraint m2Constraint = model.createConstraint(constraintName, constraint.getType());
            // Set title, desc and parameters
            setConstraintOtherData(constraint, m2Constraint, null);
        }
    }
    // Add imports
    for (Pair<String, String> uriPrefix : namespacesToImport) {
        // Don't import the already defined namespace
        if (!namespaceURI.equals(uriPrefix.getFirst())) {
            model.createImport(uriPrefix.getFirst(), uriPrefix.getSecond());
        }
    }
    return model;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CustomType(org.alfresco.rest.api.model.CustomType) M2Constraint(org.alfresco.repo.dictionary.M2Constraint) M2Type(org.alfresco.repo.dictionary.M2Type) M2Model(org.alfresco.repo.dictionary.M2Model) CustomAspect(org.alfresco.rest.api.model.CustomAspect) M2Aspect(org.alfresco.repo.dictionary.M2Aspect) CustomModelConstraint(org.alfresco.rest.api.model.CustomModelConstraint) 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