use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project ballerina by ballerina-lang.
the class CommandUtil method getServiceDocumentationByPosition.
/**
* Get the Documentation attachment for the service.
* @param bLangPackage BLangPackage built
* @param line Start line of the service in the source
* @return {@link String} Documentation attachment for the service
*/
static DocAttachmentInfo getServiceDocumentationByPosition(BLangPackage bLangPackage, int line) {
// TODO: Currently resource position is invalid and we use the annotation attachment positions.
for (TopLevelNode topLevelNode : bLangPackage.topLevelNodes) {
if (topLevelNode instanceof BLangService) {
BLangService serviceNode = (BLangService) topLevelNode;
DiagnosticPos servicePos = CommonUtil.toZeroBasedPosition(serviceNode.getPosition());
List<BLangAnnotationAttachment> annotationAttachments = serviceNode.getAnnotationAttachments();
if (!annotationAttachments.isEmpty()) {
DiagnosticPos lastAttachmentPos = CommonUtil.toZeroBasedPosition(annotationAttachments.get(annotationAttachments.size() - 1).getPosition());
if (lastAttachmentPos.getEndLine() < line && line < servicePos.getEndLine()) {
return getServiceNodeDocumentation(serviceNode, lastAttachmentPos.getEndLine() + 1);
}
} else if (servicePos.getStartLine() == line) {
return getServiceNodeDocumentation(serviceNode, line);
}
}
}
return null;
}
use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project ballerina by ballerina-lang.
the class CompilerPluginRunner method notifyProcessors.
private void notifyProcessors(List<BLangAnnotationAttachment> attachments, BiConsumer<CompilerPlugin, List<AnnotationAttachmentNode>> notifier) {
Map<CompilerPlugin, List<AnnotationAttachmentNode>> attachmentMap = new HashMap<>();
for (BLangAnnotationAttachment attachment : attachments) {
DefinitionID aID = new DefinitionID(attachment.annotationSymbol.pkgID.getName().value, attachment.annotationName.value);
if (!processorMap.containsKey(aID)) {
continue;
}
List<CompilerPlugin> procList = processorMap.get(aID);
procList.forEach(proc -> {
List<AnnotationAttachmentNode> attachmentNodes = attachmentMap.computeIfAbsent(proc, k -> new ArrayList<>());
attachmentNodes.add(attachment);
});
}
for (CompilerPlugin processor : attachmentMap.keySet()) {
notifier.accept(processor, Collections.unmodifiableList(attachmentMap.get(processor)));
}
}
use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project ballerina by ballerina-lang.
the class SemanticAnalyzer method visit.
public void visit(BLangAnnotationAttachment annAttachmentNode) {
BSymbol symbol = this.symResolver.resolveAnnotation(annAttachmentNode.pos, env, names.fromString(annAttachmentNode.pkgAlias.getValue()), names.fromString(annAttachmentNode.getAnnotationName().getValue()));
if (symbol == this.symTable.notFoundSymbol) {
this.dlog.error(annAttachmentNode.pos, DiagnosticCode.UNDEFINED_ANNOTATION, annAttachmentNode.getAnnotationName().getValue());
return;
}
// Validate Attachment Point against the Annotation Definition.
BAnnotationSymbol annotationSymbol = (BAnnotationSymbol) symbol;
annAttachmentNode.annotationSymbol = annotationSymbol;
if (annotationSymbol.getAttachmentPoints() != null && annotationSymbol.getAttachmentPoints().size() > 0) {
BLangAnnotationAttachmentPoint[] attachmentPointsArrray = new BLangAnnotationAttachmentPoint[annotationSymbol.getAttachmentPoints().size()];
Optional<BLangAnnotationAttachmentPoint> matchingAttachmentPoint = Arrays.stream(annotationSymbol.getAttachmentPoints().toArray(attachmentPointsArrray)).filter(attachmentPoint -> attachmentPoint.equals(annAttachmentNode.attachmentPoint)).findAny();
if (!matchingAttachmentPoint.isPresent()) {
String msg = annAttachmentNode.attachmentPoint.getAttachmentPoint().getValue();
this.dlog.error(annAttachmentNode.pos, DiagnosticCode.ANNOTATION_NOT_ALLOWED, annotationSymbol, msg);
}
}
// Validate Annotation Attachment data struct against Annotation Definition struct.
validateAnnotationAttachmentExpr(annAttachmentNode, annotationSymbol);
}
use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project carbon-business-process by wso2.
the class TaskOperationsImpl method addAttachment.
/**
* Add attachment to a task. Returns an identifier for the attachment.
* @param taskIdentifier : task identifier
* @param name : attachment name
* @param accessType : access type
* @param contentType : content type
* @param attachment : attachment ID (String)
* @return
* @throws IllegalStateFault
* @throws IllegalOperationFault
* @throws IllegalArgumentFault
* @throws IllegalAccessFault
*/
public boolean addAttachment(URI taskIdentifier, String name, String accessType, String contentType, Object attachment) throws IllegalStateFault, IllegalOperationFault, IllegalArgumentFault, IllegalAccessFault {
final Long taskId = validateTaskId(taskIdentifier);
final String attachmentID = (String) attachment;
try {
Boolean isAdded = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getScheduler().execTransaction(new Callable<Boolean>() {
public Boolean call() throws Exception {
HumanTaskEngine engine = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine();
HumanTaskDAOConnection daoConn = engine.getDaoConnectionFactory().getConnection();
TaskDAO taskDAO = daoConn.getTask(taskId);
validateTaskTenant(taskDAO);
try {
boolean isAdded = taskDAO.addAttachment(TransformerUtils.generateAttachmentDAOFromID(taskDAO, attachmentID));
if (!isAdded) {
throw new HumanTaskException("Attachment with id: " + attachmentID + "was not associated " + "task with id:" + taskId);
}
return isAdded;
} catch (HumanTaskException ex) {
String errMsg = "getAttachmentInfos operation failed. Reason: ";
log.error(errMsg + ex.getLocalizedMessage(), ex);
throw ex;
}
}
});
return isAdded;
} catch (Exception ex) {
handleException(ex);
}
return false;
}
use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project carbon-business-process by wso2.
the class AttachmentUploadClient method addUploadedFileItem.
/**
* Upload the attachment and return the attachment id
* @param fileItemData wrapper for the attachment
* @return attachment id for the uploaded attachment
* @throws AttachmentMgtException If an error occurred in the back-end component
* @throws RemoteException if an error during the communication
*/
public String addUploadedFileItem(FileItemData fileItemData) throws AttachmentMgtException, RemoteException, ExceptionException {
DataHandler handler = fileItemData.getDataHandler();
TAttachment attachment = new TAttachment();
attachment.setName(handler.getName());
attachment.setContentType(handler.getContentType());
attachment.setCreatedBy(getUserName());
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
attachment.setCreatedTime(calendar);
attachment.setContent(handler);
String attachmentID = stub.add(attachment);
log.info("Attachment was uploaded with id:" + attachmentID);
return attachmentID;
}
Aggregations