use of org.structr.common.SecurityContext in project structr by structr.
the class GetTypeInfoCommand method processMessage.
@Override
public void processMessage(final WebSocketMessage webSocketData) {
final String type = (String) webSocketData.getNodeData().get("type");
if (type == null) {
logger.warn("Node type given not found");
getWebSocket().send(MessageBuilder.status().code(400).build(), true);
}
final SecurityContext securityContext = getWebSocket().getSecurityContext();
final App app = StructrApp.getInstance(securityContext);
final SchemaNode typeNode;
try {
typeNode = app.nodeQuery(SchemaNode.class).andName(type).getFirst();
if (typeNode != null) {
webSocketData.setResult(Arrays.asList(typeNode));
// send only over local connection (no broadcast)
getWebSocket().send(webSocketData, true);
}
} catch (FrameworkException ex) {
logger.error("", ex);
getWebSocket().send(MessageBuilder.status().code(500).build(), true);
}
}
use of org.structr.common.SecurityContext in project structr by structr.
the class ImportCommand method processMessage.
@Override
public void processMessage(final WebSocketMessage webSocketData) {
final SecurityContext securityContext = getWebSocket().getSecurityContext();
final Map<String, Object> properties = webSocketData.getNodeData();
final String code = (String) properties.get("code");
final String address = (String) properties.get("address");
final String name = (String) properties.get("name");
final boolean publicVisible = (Boolean) properties.get("publicVisible");
final boolean authVisible = (Boolean) properties.get("authVisible");
final boolean processDeploymentInfo = (Boolean) properties.get("processDeploymentInfo");
try {
final Importer pageImporter = new Importer(securityContext, code, address, name, publicVisible, authVisible);
if (processDeploymentInfo) {
pageImporter.setIsDeployment(true);
pageImporter.setCommentHandler(new DeploymentCommentHandler());
}
final boolean parseOk = pageImporter.parse();
if (parseOk) {
if (address != null) {
logger.info("Successfully parsed {}", address);
getWebSocket().send(MessageBuilder.status().code(200).message("Successfully parsed address " + address).build(), true);
}
String pageId = pageImporter.readPage().getUuid();
Map<String, Object> resultData = new HashMap();
if (pageId != null) {
resultData.put("id", pageId);
getWebSocket().send(MessageBuilder.status().code(200).message("Successfully created page " + name).data(resultData).build(), true);
} else {
getWebSocket().send(MessageBuilder.status().code(400).message("Error while creating page " + name).data(resultData).build(), true);
}
}
} catch (FrameworkException fex) {
logger.warn("Error while importing content", fex);
getWebSocket().send(MessageBuilder.status().code(fex.getStatus()).message(fex.getMessage()).build(), true);
}
}
use of org.structr.common.SecurityContext in project structr by structr.
the class InsertCommand method processMessage.
@Override
public void processMessage(final WebSocketMessage webSocketData) {
final SecurityContext securityContext = getWebSocket().getSecurityContext();
final App app = StructrApp.getInstance(securityContext);
// new node properties
final Map<String, Object> properties = webSocketData.getNodeData();
String parentId = (String) properties.get("id");
final Map<String, Object> relData = webSocketData.getRelData();
if (parentId != null) {
DOMNode parentNode = (DOMNode) getNode(parentId);
DOMNode nodeToInsert = null;
try {
PropertyMap nodeProperties = PropertyMap.inputTypeToJavaType(securityContext, properties);
nodeToInsert = app.create(DOMNode.class, nodeProperties);
} catch (FrameworkException fex) {
logger.warn("Could not create node.", fex);
getWebSocket().send(MessageBuilder.status().code(fex.getStatus()).message(fex.getMessage()).build(), true);
}
if ((nodeToInsert != null) && (parentNode != null)) {
try {
PropertyMap relProperties = PropertyMap.inputTypeToJavaType(securityContext, relData);
app.create(parentNode, nodeToInsert, parentNode.getChildLinkType(), relProperties);
} catch (FrameworkException t) {
getWebSocket().send(MessageBuilder.status().code(400).message(t.getMessage()).build(), true);
}
} else {
getWebSocket().send(MessageBuilder.status().code(404).build(), true);
}
} else {
getWebSocket().send(MessageBuilder.status().code(400).message("Insertion of new node failed.").build(), true);
}
}
use of org.structr.common.SecurityContext in project structr by structr.
the class AbstractCommand method getRelationship.
/**
* Returns the relationship to which the uuid parameter
* of this command refers to.
*
* @param id
* @return the node
*/
public AbstractRelationship getRelationship(final String id) {
if (id == null) {
return null;
}
final SecurityContext securityContext = getWebSocket().getSecurityContext();
final App app = StructrApp.getInstance(securityContext);
try (final Tx tx = app.tx()) {
final AbstractRelationship rel = (AbstractRelationship) app.getRelationshipById(id);
tx.success();
return rel;
} catch (FrameworkException fex) {
logger.warn("Unable to get relationship", fex);
}
return null;
}
use of org.structr.common.SecurityContext in project structr by structr.
the class RelationshipFactory method instantiateWithType.
@Override
public T instantiateWithType(final Relationship relationship, final Class<T> relClass, final Relationship pathSegment, final boolean isCreation) {
// cannot instantiate relationship without type
if (relClass == null) {
return null;
}
logger.debug("Instantiate relationship with type {}", relClass.getName());
SecurityContext securityContext = factoryProfile.getSecurityContext();
T newRel = null;
try {
newRel = relClass.newInstance();
} catch (Throwable t) {
logger.warn("", t);
newRel = null;
}
if (newRel == null) {
System.out.println("##################### newRel was null, using generic relationship..");
newRel = (T) StructrApp.getConfiguration().getFactoryDefinition().createGenericRelationship();
}
newRel.init(securityContext, relationship, relClass);
newRel.onRelationshipInstantiation();
return newRel;
}
Aggregations