use of org.alfresco.filesys.repo.rules.operations.CreateFileOperation in project alfresco-repository by Alfresco.
the class ScenarioCreateShuffle method createInstance.
@Override
public ScenarioInstance createInstance(final EvaluatorContext ctx, Operation operation) {
/**
* This scenario is triggered by a create of a file matching
* the pattern
*/
if (operation instanceof CreateFileOperation) {
CreateFileOperation c = (CreateFileOperation) operation;
Matcher m = pattern.matcher(c.getName());
if (m.matches()) {
if (logger.isDebugEnabled()) {
logger.debug("New Scenario Create Shuffle Instance pattern:" + strPattern);
}
ScenarioCreateShuffleInstance instance = new ScenarioCreateShuffleInstance();
instance.setTimeout(timeout);
instance.setRanking(ranking);
return instance;
}
}
// No not interested.
return null;
}
use of org.alfresco.filesys.repo.rules.operations.CreateFileOperation in project alfresco-repository by Alfresco.
the class ScenarioRenameShuffleInstance method evaluate.
/**
* Evaluate the next operation
* @param operation Operation
*/
public Command evaluate(Operation operation) {
/**
* Anti-pattern : timeout
*/
Date now = new Date();
if (now.getTime() > startTime.getTime() + getTimeout()) {
if (logger.isDebugEnabled()) {
logger.debug("Instance timed out");
}
isComplete = true;
return null;
}
switch(state) {
case NONE:
if (operation instanceof RenameFileOperation) {
logger.debug("New scenario initialised");
RenameFileOperation r = (RenameFileOperation) operation;
this.from = r.getFrom();
this.to = r.getTo();
state = InternalState.INITIALISED;
}
break;
case INITIALISED:
if (operation instanceof CreateFileOperation) {
CreateFileOperation c = (CreateFileOperation) operation;
if (from.equals(c.getName())) {
logger.debug("transition to LOOK_FOR_DELETE");
state = InternalState.LOOK_FOR_DELETE;
}
}
break;
case LOOK_FOR_DELETE:
if (operation instanceof DeleteFileOperation) {
DeleteFileOperation d = (DeleteFileOperation) operation;
if (to.equals(d.getName())) {
logger.debug("Rename shuffle complete - fire!");
String[] paths = FileName.splitPath(d.getPath());
String oldFolder = paths[0];
/**
* Shuffle is as follows
* a) Copy content from File to File~
* b) Delete File
* c) Rename File~ to File
*/
ArrayList<Command> commands = new ArrayList<Command>();
CopyContentCommand copyContent = new CopyContentCommand(from, to, d.getRootNodeRef(), oldFolder + "\\" + from, oldFolder + "\\" + to);
RenameFileCommand r1 = new RenameFileCommand(to, from, d.getRootNodeRef(), oldFolder + "\\" + to, oldFolder + "\\" + from);
DeleteFileCommand d1 = new DeleteFileCommand(from, d.getRootNodeRef(), oldFolder + "\\" + from);
commands.add(copyContent);
commands.add(d1);
commands.add(r1);
logger.debug("Scenario complete");
isComplete = true;
return new CompoundCommand(commands);
}
}
}
return null;
}
use of org.alfresco.filesys.repo.rules.operations.CreateFileOperation in project alfresco-repository by Alfresco.
the class ScenarioTempDeleteShuffle method createInstance.
@Override
public ScenarioInstance createInstance(final EvaluatorContext ctx, Operation operation) {
/**
* This scenario is triggered by a delete of a file matching
* the pattern
*/
if (operation instanceof CreateFileOperation) {
CreateFileOperation c = (CreateFileOperation) operation;
// check whether file is below .TemporaryItems
String path = c.getPath();
// if path contains .TemporaryItems
Matcher d = tempDirPattern.matcher(path);
if (d.matches()) {
logger.debug("pattern matches temp dir folder so this is a new create in a temp dir");
Matcher m = pattern.matcher(c.getName());
if (m.matches()) {
// and how to lock - since we are already have one lock on the scenarios/folder here
// this is a potential deadlock and synchronization bottleneck
Map<String, String> createdTempFiles = (Map<String, String>) ctx.getSessionState().get(SCENARIO_KEY);
if (createdTempFiles == null) {
synchronized (ctx.getSessionState()) {
logger.debug("created new temp file map and added it to the session state");
createdTempFiles = (Map<String, String>) ctx.getSessionState().get(SCENARIO_KEY);
if (createdTempFiles == null) {
createdTempFiles = Collections.synchronizedMap(new MaxSizeMap<String, String>(5, false));
ctx.getSessionState().put(SCENARIO_KEY, createdTempFiles);
}
}
}
createdTempFiles.put(c.getName(), c.getName());
// TODO - Return a different scenario instance here ???
// So it can time out and have anti-patterns etc?
}
}
}
if (operation instanceof MoveFileOperation) {
MoveFileOperation mf = (MoveFileOperation) operation;
// check whether file is below .TemporaryItems
String path = mf.getFromPath();
// if path contains .TemporaryItems
Matcher d = tempDirPattern.matcher(path);
if (d.matches()) {
logger.debug("pattern matches temp dir folder so this is a new create in a temp dir");
Matcher m = pattern.matcher(mf.getFrom());
if (m.matches()) {
// and how to lock - since we are already have one lock on the scenarios/folder here
// this is a potential deadlock and synchronization bottleneck
Map<String, String> createdTempFiles = (Map<String, String>) ctx.getSessionState().get(SCENARIO_KEY);
if (createdTempFiles == null) {
synchronized (ctx.getSessionState()) {
logger.debug("created new temp file map and added it to the session state");
createdTempFiles = (Map<String, String>) ctx.getSessionState().get(SCENARIO_KEY);
if (createdTempFiles == null) {
createdTempFiles = Collections.synchronizedMap(new MaxSizeMap<String, String>(5, false));
ctx.getSessionState().put(SCENARIO_KEY, createdTempFiles);
}
}
}
createdTempFiles.remove(mf.getFrom());
// TODO - Return a different scenario instance here ???
// So it can time out and have anti-patterns etc?
}
}
}
if (operation instanceof DeleteFileOperation) {
DeleteFileOperation c = (DeleteFileOperation) operation;
Matcher m = pattern.matcher(c.getName());
if (m.matches()) {
Map<String, String> createdTempFiles = (Map<String, String>) ctx.getSessionState().get(SCENARIO_KEY);
if (createdTempFiles != null) {
if (createdTempFiles.containsKey(c.getName())) {
if (logger.isDebugEnabled()) {
logger.debug("New Scenario Temp Delete Shuffle Instance:" + c.getName());
}
ScenarioTempDeleteShuffleInstance instance = new ScenarioTempDeleteShuffleInstance();
instance.setTimeout(timeout);
instance.setRanking(ranking);
return instance;
}
}
}
}
// No not interested.
return null;
}
use of org.alfresco.filesys.repo.rules.operations.CreateFileOperation in project alfresco-repository by Alfresco.
the class NonTransactionalRuleContentDiskDriver method createFile.
@Override
public NetworkFile createFile(SrvSession sess, TreeConnection tree, FileOpenParams params) throws IOException {
try {
int attr = params.getAttributes();
if (logger.isDebugEnabled()) {
int sharedAccess = params.getSharedAccess();
String strSharedAccess = SharingMode.getSharingModeAsString(sharedAccess);
logger.debug("createFile:" + params.getPath() + ", isDirectory: " + params.isDirectory() + ", isStream: " + params.isStream() + ", readOnlyAccess: " + params.isReadOnlyAccess() + ", readWriteAccess: " + params.isReadWriteAccess() + ", writeOnlyAccess:" + params.isWriteOnlyAccess() + ", attributesOnlyAccess:" + params.isAttributesOnlyAccess() + ", sequentialAccessOnly:" + params.isSequentialAccessOnly() + ", requestBatchOpLock:" + params.requestBatchOpLock() + ", requestExclusiveOpLock:" + params.requestExclusiveOpLock() + ", isDeleteOnClose:" + params.isDeleteOnClose() + ", sharedAccess: " + strSharedAccess + ", allocationSize: " + params.getAllocationSize() + ", isHidden:" + FileAttribute.isHidden(attr) + ", isSystem:" + FileAttribute.isSystem(attr));
}
long creationDateTime = params.getCreationDateTime();
if (creationDateTime != 0) {
logger.debug("creationDateTime is set:" + new Date(creationDateTime));
}
ContentContext tctx = (ContentContext) tree.getContext();
NodeRef rootNode = tctx.getRootNode();
String[] paths = FileName.splitPath(params.getPath());
String folder = paths[0];
String file = paths[1];
DriverState driverState = getDriverState(sess);
EvaluatorContext ctx = getEvaluatorContext(driverState, folder);
Operation o = new CreateFileOperation(file, rootNode, params.getPath(), params.getAllocationSize(), FileAttribute.isHidden(attr));
Command c = ruleEvaluator.evaluate(ctx, o);
Object ret = commandExecutor.execute(sess, tree, c);
if (ret != null && ret instanceof NetworkFile) {
return (NetworkFile) ret;
} else {
// Error - contact broken
logger.error("contract broken - NetworkFile not returned. " + ret == null ? "Return value is null" : ret);
return null;
}
} catch (org.alfresco.repo.security.permissions.AccessDeniedException ade) {
throw new AccessDeniedException("Unable to create file " + params.getPath(), ade);
}
}
use of org.alfresco.filesys.repo.rules.operations.CreateFileOperation in project alfresco-repository by Alfresco.
the class ScenarioLockedDeleteShuffle method createInstance.
@Override
public ScenarioInstance createInstance(final EvaluatorContext ctx, Operation operation) {
/**
* This scenario is triggered by a create of a file matching
* the pattern
*/
if (operation instanceof CreateFileOperation) {
CreateFileOperation c = (CreateFileOperation) operation;
Matcher m = pattern.matcher(c.getName());
if (m.matches()) {
if (logger.isDebugEnabled()) {
logger.debug("New Scenario Locked Delete Shuffle Instance pattern:" + strPattern);
}
ScenarioLockedDeleteShuffleInstance instance = new ScenarioLockedDeleteShuffleInstance();
instance.setTimeout(timeout);
instance.setRanking(ranking);
return instance;
}
}
// No not interested.
return null;
}
Aggregations