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);
}
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;
}
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);
}
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();
}
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;
}
Aggregations