use of org.alfresco.service.cmr.repository.StoreRef in project alfresco-remote-api by Alfresco.
the class NodesGet method executeImpl.
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status) {
try {
Content content = req.getContent();
if (content == null) {
throw new WebScriptException("Failed to convert request to String");
}
JSONObject o = new JSONObject(content.getContent());
JSONArray aTxnIds = o.has("txnIds") ? o.getJSONArray("txnIds") : null;
Long fromTxnId = o.has("fromTxnId") ? o.getLong("fromTxnId") : null;
Long toTxnId = o.has("toTxnId") ? o.getLong("toTxnId") : null;
Long fromNodeId = o.has("fromNodeId") ? o.getLong("fromNodeId") : null;
Long toNodeId = o.has("toNodeId") ? o.getLong("toNodeId") : null;
Set<QName> excludeAspects = null;
if (o.has("excludeAspects")) {
JSONArray aExcludeAspects = o.getJSONArray("excludeAspects");
excludeAspects = new HashSet<QName>(aExcludeAspects.length());
for (int i = 0; i < aExcludeAspects.length(); i++) {
excludeAspects.add(QName.createQName(aExcludeAspects.getString(i).trim()));
}
}
Set<QName> includeAspects = null;
if (o.has("includeAspects")) {
JSONArray aIncludeAspects = o.getJSONArray("includeAspects");
includeAspects = new HashSet<QName>(aIncludeAspects.length());
for (int i = 0; i < aIncludeAspects.length(); i++) {
includeAspects.add(QName.createQName(aIncludeAspects.getString(i).trim()));
}
}
Set<QName> excludeNodeTypes = null;
if (o.has("excludeNodeTypes")) {
JSONArray aExcludeNodeTypes = o.getJSONArray("excludeNodeTypes");
excludeNodeTypes = new HashSet<QName>(aExcludeNodeTypes.length());
for (int i = 0; i < aExcludeNodeTypes.length(); i++) {
excludeNodeTypes.add(QName.createQName(aExcludeNodeTypes.getString(i).trim()));
}
}
Set<QName> includeNodeTypes = null;
if (o.has("includeNodeTypes")) {
JSONArray aIncludeNodeTypes = o.getJSONArray("includeNodeTypes");
includeNodeTypes = new HashSet<QName>(aIncludeNodeTypes.length());
for (int i = 0; i < aIncludeNodeTypes.length(); i++) {
includeNodeTypes.add(QName.createQName(aIncludeNodeTypes.getString(i).trim()));
}
}
// 0 or Integer.MAX_VALUE => ignore
int maxResults = o.has("maxResults") ? o.getInt("maxResults") : 0;
String storeProtocol = o.has("storeProtocol") ? o.getString("storeProtocol") : null;
String storeIdentifier = o.has("storeIdentifier") ? o.getString("storeIdentifier") : null;
List<Long> txnIds = null;
if (aTxnIds != null) {
txnIds = new ArrayList<Long>(aTxnIds.length());
for (int i = 0; i < aTxnIds.length(); i++) {
txnIds.add(aTxnIds.getLong(i));
}
}
String shardProperty = o.has("shardProperty") ? o.getString("shardProperty") : null;
NodeParameters nodeParameters = new NodeParameters();
nodeParameters.setTransactionIds(txnIds);
nodeParameters.setFromTxnId(fromTxnId);
nodeParameters.setToTxnId(toTxnId);
nodeParameters.setFromNodeId(fromNodeId);
nodeParameters.setToNodeId(toNodeId);
nodeParameters.setExcludeAspects(excludeAspects);
nodeParameters.setIncludeAspects(includeAspects);
nodeParameters.setExcludeNodeTypes(excludeNodeTypes);
nodeParameters.setIncludeNodeTypes(includeNodeTypes);
nodeParameters.setShardProperty(shardProperty);
StoreRef storeRef = null;
if (AuthenticationUtil.isMtEnabled()) {
// MT - use Java filter (post query) and then add tenant context for each node
storeRef = new StoreRef(storeProtocol, storeIdentifier);
} else {
// non-MT - use DB filter (in query)
nodeParameters.setStoreProtocol(storeProtocol);
nodeParameters.setStoreIdentifier(storeIdentifier);
}
nodeParameters.setMaxResults(maxResults);
WebNodeQueryCallback nodeQueryCallback = new WebNodeQueryCallback(maxResults, storeRef, tenantService, qnameDAO);
solrTrackingComponent.getNodes(nodeParameters, nodeQueryCallback);
Map<String, Object> model = new HashMap<String, Object>(1, 1.0f);
List<NodeRecord> nodes = nodeQueryCallback.getNodes();
model.put("nodes", nodes);
if (logger.isDebugEnabled()) {
logger.debug("Result: \n\tRequest: " + req + "\n\tModel: " + model);
}
return model;
} catch (IOException e) {
throw new WebScriptException("IO exception parsing request", e);
} catch (JSONException e) {
throw new WebScriptException("Invalid JSON", e);
}
}
use of org.alfresco.service.cmr.repository.StoreRef in project alfresco-remote-api by Alfresco.
the class WebDAVServlet method initializeRootNode.
/**
* @param storeValue String
* @param rootPath String
* @param context WebApplicationContext
* @param nodeService NodeService
* @param searchService SearchService
* @param namespaceService NamespaceService
* @param tenantService TenantService
* @param m_transactionService TransactionService
*/
private void initializeRootNode(String storeValue, String rootPath, WebApplicationContext context, NodeService nodeService, SearchService searchService, NamespaceService namespaceService, TenantService tenantService, TransactionService m_transactionService) {
// Use the system user as the authenticated context for the filesystem initialization
AuthenticationContext authComponent = (AuthenticationContext) context.getBean("authenticationContext");
authComponent.setSystemUserAsCurrentUser();
// Wrap the initialization in a transaction
UserTransaction tx = m_transactionService.getUserTransaction(true);
try {
if (tx != null)
tx.begin();
StoreRef storeRef = new StoreRef(storeValue);
if (nodeService.exists(storeRef) == false) {
throw new RuntimeException("No store for path: " + storeRef);
}
NodeRef storeRootNodeRef = nodeService.getRootNode(storeRef);
List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, rootPath, null, namespaceService, false);
if (nodeRefs.size() > 1) {
throw new RuntimeException("Multiple possible children for : \n" + " path: " + rootPath + "\n" + " results: " + nodeRefs);
} else if (nodeRefs.size() == 0) {
throw new RuntimeException("Node is not found for : \n" + " root path: " + rootPath);
}
defaultRootNode = nodeRefs.get(0);
// Commit the transaction
if (tx != null)
tx.commit();
} catch (Exception ex) {
logger.error(ex);
} finally {
// Clear the current system user
authComponent.clearCurrentSecurityContext();
}
}
use of org.alfresco.service.cmr.repository.StoreRef in project alfresco-remote-api by Alfresco.
the class AbstractCommentsWebScript method parseRequestForNodeRef.
/**
* returns the nodeRef from web script request
* @param req
* @return
*/
protected NodeRef parseRequestForNodeRef(WebScriptRequest req) {
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
String storeType = templateVars.get("store_type");
String storeId = templateVars.get("store_id");
String nodeId = templateVars.get("id");
// create the NodeRef and ensure it is valid
StoreRef storeRef = new StoreRef(storeType, storeId);
return new NodeRef(storeRef, nodeId);
}
use of org.alfresco.service.cmr.repository.StoreRef in project alfresco-remote-api by Alfresco.
the class TransactionsGet method executeImpl.
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status) {
String minTxnIdParam = req.getParameter("minTxnId");
String fromCommitTimeParam = req.getParameter("fromCommitTime");
String maxTxnIdParam = req.getParameter("maxTxnId");
String toCommitTimeParam = req.getParameter("toCommitTime");
String maxResultsParam = req.getParameter("maxResults");
String baseUrl = req.getParameter("baseUrl");
String hostName = req.getParameter("hostName");
String template = req.getParameter("template");
String instance = req.getParameter("instance");
String numberOfShards = req.getParameter("numberOfShards");
String port = req.getParameter("port");
String stores = req.getParameter("stores");
String isMaster = req.getParameter("isMaster");
String hasContent = req.getParameter("hasContent");
String shardMethod = req.getParameter("shardMethod");
String lastUpdated = req.getParameter("lastUpdated");
String lastIndexedChangeSetCommitTime = req.getParameter("lastIndexedChangeSetCommitTime");
String lastIndexedChangeSetId = req.getParameter("lastIndexedChangeSetId");
String lastIndexedTxCommitTime = req.getParameter("lastIndexedTxCommitTime");
String lastIndexedTxId = req.getParameter("lastIndexedTxId");
if (baseUrl != null) {
ShardState shardState = ShardStateBuilder.shardState().withMaster(Boolean.valueOf(isMaster)).withLastUpdated(Long.valueOf(lastUpdated)).withLastIndexedChangeSetCommitTime(Long.valueOf(lastIndexedChangeSetCommitTime)).withLastIndexedChangeSetId(Long.valueOf(lastIndexedChangeSetId)).withLastIndexedTxCommitTime(Long.valueOf(lastIndexedTxCommitTime)).withLastIndexedTxId(Long.valueOf(lastIndexedTxId)).withShardInstance().withBaseUrl(baseUrl).withPort(Integer.valueOf(port)).withHostName(hostName).withShard().withInstance(Integer.valueOf(instance)).withFloc().withNumberOfShards(Integer.valueOf(numberOfShards)).withTemplate(template).withHasContent(Boolean.valueOf(hasContent)).withShardMethod(ShardMethodEnum.getShardMethod(shardMethod)).endFloc().endShard().endShardInstance().build();
for (String store : stores.split(",")) {
shardState.getShardInstance().getShard().getFloc().getStoreRefs().add(new StoreRef(store));
}
for (String pName : req.getParameterNames()) {
if (pName.startsWith("floc.property.")) {
String key = pName.substring("floc.property.".length());
String value = req.getParameter(pName);
shardState.getShardInstance().getShard().getFloc().getPropertyBag().put(key, value);
} else if (pName.startsWith("state.property.")) {
String key = pName.substring("state.property.".length());
String value = req.getParameter(pName);
shardState.getPropertyBag().put(key, value);
}
}
solrTrackingComponent.registerShardState(shardState);
}
Long minTxnId = (minTxnIdParam == null ? null : Long.valueOf(minTxnIdParam));
Long fromCommitTime = (fromCommitTimeParam == null ? null : Long.valueOf(fromCommitTimeParam));
Long maxTxnId = (maxTxnIdParam == null ? null : Long.valueOf(maxTxnIdParam));
Long toCommitTime = (toCommitTimeParam == null ? null : Long.valueOf(toCommitTimeParam));
int maxResults = (maxResultsParam == null ? 1024 : Integer.valueOf(maxResultsParam));
List<Transaction> transactions = solrTrackingComponent.getTransactions(minTxnId, fromCommitTime, maxTxnId, toCommitTime, maxResults);
Map<String, Object> model = new HashMap<String, Object>(1, 1.0f);
model.put("transactions", transactions);
Long maxTxnCommitTime = solrTrackingComponent.getMaxTxnCommitTime();
if (maxTxnCommitTime != null) {
model.put("maxTxnCommitTime", maxTxnCommitTime);
}
Long maxTxnIdOnServer = solrTrackingComponent.getMaxTxnId();
if (maxTxnIdOnServer != null) {
model.put("maxTxnId", maxTxnIdOnServer);
}
if (logger.isDebugEnabled()) {
logger.debug("Result: \n\tRequest: " + req + "\n\tModel: " + model);
}
return model;
}
use of org.alfresco.service.cmr.repository.StoreRef in project alfresco-remote-api by Alfresco.
the class AbstractDiscussionWebScript method executeImpl.
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
if (templateVars == null) {
String error = "No parameters supplied";
throw new WebScriptException(Status.STATUS_BAD_REQUEST, error);
}
// Parse the JSON, if supplied
JSONObject json = null;
String contentType = req.getContentType();
if (contentType != null && contentType.indexOf(';') != -1) {
contentType = contentType.substring(0, contentType.indexOf(';'));
}
if (MimetypeMap.MIMETYPE_JSON.equals(contentType)) {
JSONParser parser = new JSONParser();
try {
json = (JSONObject) parser.parse(req.getContent().getContent());
} catch (IOException io) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid JSON: " + io.getMessage());
} catch (ParseException pe) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid JSON: " + pe.getMessage());
}
}
// Did they request it by node reference or site?
NodeRef nodeRef = null;
SiteInfo site = null;
TopicInfo topic = null;
PostInfo post = null;
if (templateVars.containsKey("site")) {
// Site, and optionally topic
String siteName = templateVars.get("site");
site = siteService.getSite(siteName);
if (site == null) {
String error = "Could not find site: " + siteName;
throw new WebScriptException(Status.STATUS_NOT_FOUND, error);
}
// Did they give a topic name too?
if (templateVars.containsKey("path")) {
String name = templateVars.get("path");
topic = discussionService.getTopic(site.getShortName(), name);
if (topic == null) {
String error = "Could not find topic '" + name + "' for site '" + site.getShortName() + "'";
throw new WebScriptException(Status.STATUS_NOT_FOUND, error);
}
nodeRef = topic.getNodeRef();
} else {
// The NodeRef is the container (if it exists)
if (siteService.hasContainer(siteName, DiscussionServiceImpl.DISCUSSION_COMPONENT)) {
nodeRef = siteService.getContainer(siteName, DiscussionServiceImpl.DISCUSSION_COMPONENT);
}
}
} else if (templateVars.containsKey("store_type") && templateVars.containsKey("store_id") && templateVars.containsKey("id")) {
// NodeRef, normally Topic or Discussion
StoreRef store = new StoreRef(templateVars.get("store_type"), templateVars.get("store_id"));
nodeRef = new NodeRef(store, templateVars.get("id"));
if (!nodeService.exists(nodeRef)) {
String error = "Could not find node: " + nodeRef;
throw new WebScriptException(Status.STATUS_NOT_FOUND, error);
}
// Try to build the appropriate object for it
Pair<TopicInfo, PostInfo> objects = discussionService.getForNodeRef(nodeRef);
if (objects != null) {
topic = objects.getFirst();
post = objects.getSecond();
}
// See if it's actually attached to a site
if (topic != null) {
NodeRef container = topic.getContainerNodeRef();
if (container != null) {
NodeRef maybeSite = nodeService.getPrimaryParent(container).getParentRef();
if (maybeSite != null) {
// Try to make it a site, will return Null if it isn't one
site = siteService.getSite(maybeSite);
}
}
}
} else {
String error = "Unsupported template parameters found";
throw new WebScriptException(Status.STATUS_BAD_REQUEST, error);
}
// Have the real work done
return executeImpl(site, nodeRef, topic, post, req, json, status, cache);
}
Aggregations