Extracting requierement properties from Capella - m2doc

I would like to extract the requirements data in capella using m2doc, requirements (SystemFunctionalRequirement) are located in a "RequirementsPkg" package in System analysis, thanks to the "m:RequirementsPkg.eContents().summary" command I managed to retrieve the summary of all requirements but I would like to retrieve the name and the summary of a specific requirement.
Can you help me ?
Thanks in advance

This mechanism is deprecated. You should use the requirement extension.
Starting from the root element, you can use something like:
{ m:system.ownedArchitectures->filter(la::LogicalArchitecture).ownedRequirementPkgs.ownedRequirements.name }
With the requirement extension the easiest way is to create a service:
public List<Requirement> getRequirements(ExtensibleElement element) {
List<Requirement> res = new ArrayList<>();
for (ElementExtension extension : element.getOwnedExtensions()) {
if (extension instanceof Requirement) {
res.add((Requirement) extension);
break;
} else if (extension instanceof CapellaOutgoingRelation) {
res.add(((CapellaOutgoingRelation) extension).getTarget());
}
}
return res;
}
and call it, for instance on a diagram:
{ m:for req | '[LAB] IFE System - All Components, CEs'.representationByName().eAllContents(viewpoint::DRepresentationElement).semanticElements->filter(emde::ExtensibleElement).getRequirements() }
{ m:req.ReqIFLongName }
{ m:endfor }

Related

Reducing code duplication when testing a KtorClient

I am creating a service on top of a Ktor client. My payload is XML, and as such a simplified version of my client looks like this :
class MavenClient(private val client : HttpClient) {
private suspend fun getRemotePom(url : String) =
try{ MavenClientSuccess(client.get<POMProject>(url)) }catch (e: Exception) { MavenClientFailure(e)
}
companion object {
fun getDefaultClient(): HttpClient {
return HttpClient(Apache) {
install(JsonFeature) {
serializer = JacksonSerializer(jackson = kotlinXmlMapper)
accept(ContentType.Text.Xml)
accept(ContentType.Application.Xml)
accept(ContentType.Text.Plain)
}
}
}
}
}
Note the use of a custom XMLMapper, attached to a custom data class.
I want to test this class, and follow the documentation.
I end up with the following code for my test client :
private val mockClient = HttpClient(MockEngine) {
engine {
addHandler { request ->
when (request.url.fullUrl) {
"https://lengrand.me/minimal/1.2/minimal-1.2.pom" -> {
respond(minimalResourceStreamPom.readBytes()
, headers = headersOf("Content-Type" to listOf(ContentType.Application.Xml.toString())))
}
"https://lengrand.me/unknown/1.2/unknown-1.2.pom" -> {
respond("", HttpStatusCode.NotFound)
}
else -> error("Unhandled ${request.url.fullUrl}")
}
}
}
// TODO : How do I avoid repeating this again ? That's my implementation?!
install(JsonFeature) {
serializer = JacksonSerializer(jackson = PomParser.kotlinXmlMapper)
accept(ContentType.Text.Xml)
accept(ContentType.Application.Xml)
accept(ContentType.Text.Plain)
}
}
private val Url.hostWithPortIfRequired: String get() = if (port == protocol.defaultPort) host else hostWithPort
private val Url.fullUrl: String get() = "${protocol.name}://$hostWithPortIfRequired$fullPath"
private val mavenClient = MavenClient(mockClient)
Now, I am not worried about the Mapper itself, because I test it directly.
However what bothers me is that I essentially have to duplicate the complete logic of my client to test behaviour?
This seems very brittle, because for example it will cause my tests to fail and have to be updated if I move to Json tomorrow. Same if I start using Response Validation for example.
This is even more true for another client where I am using a defaultRequest, which I have to completely copy over as well:
private val mockClient = HttpClient(MockEngine) {
install(JsonFeature) {
serializer = JacksonSerializer(mapper)
accept(ContentType.Application.Json)
}
defaultRequest {
method = HttpMethod.Get
host = "api.github.com"
header("Accept", "application/vnd.github.v3+json")
if (GithubLogin().hasToken()) header("Authorization", GithubLogin().authToken)
}
Am I doing things wrong? Am I testing too much ? I am curious as to how I can improve this.
Thanks a lot for your input!
P.S : Unrelated but the page about testing on Ktor mentions adding the dependency to the implementation. Sounds like I should use testImplementation instead to avoid shipping the lib with my application ?
The MockEngine is designed for stubbing real HTTP client implementation to test objects that use it. The duplication problem, you encounter, lies in the fact that transforming response body responsibility belongs to the client. So I suggest either use Jackson directly to transform a response body (in this case you don't need to use JsonFeature) or extract common configuration in a extension function and call it for both engines.

Jenkins DSL Plugin (>=1.77): Use gerrit-trigger in pipelineJob

I don't know how to use the gerrit-trigger plugin in a DSL pipelineJob. According to the dsl plugin doc triggers is deprecated for pipelineJobs. And from the wiki 1.77 replaced by pipelineTriggers. So I have change my triggers section to
properties {
pipelineTriggers {
triggers {
gerrit {
events {
patchsetCreated()
}
project('**My/Git/Repo', '**')
}
}
}
}
However, when I use pipelineTriggers i get the following
ERROR: (configure_seed_jobs.groovy, line 25) No signature of method: events() is applicable for argument types: (configure_seed_jobs$_run_closure1$_closure4$_closure9$_closure10$_closure11$_closure12) values: [configure_seed_jobs$_run_closure1$_closure4$_closure9$_closure10$_closure11$_closure12#3bcd6c54]
Possible solutions: gerritProjects(), buildFailureMessage(), buildNotBuiltMessage(), buildStartMessage(), buildSuccessfulMessage(), buildUnstableMessage(), buildUnsuccessfulFilepath(), changeSubjectParameterMode(), commentTextParameterMode(), commitMessageParameterMode(), customUrl(), dependencyJobsNames(), dynamicTriggerConfiguration(), escapeQuotes(), gerritBuildFailedCodeReviewValue(), gerritBuildFailedVerifiedValue(), gerritBuildNotBuiltCodeReviewValue(), gerritBuildNotBuiltVerifiedValue(), gerritBuildStartedCodeReviewValue(), gerritBuildStartedVerifiedValue(), gerritBuildSuccessfulCodeReviewValue(), gerritBuildSuccessfulVerifiedValue(), gerritBuildUnstableCodeReviewValue(), gerritBuildUnstableVerifiedValue(), gerritSlaveId(), nameAndEmailParameterMode(), notificationLevel(), serverName(), silentMode(), silentStartMode(), skipVote(), triggerConfigURL(), triggerOnEvents()
What am I missing?
I had the same problem, because either events{..} or project() is no more available to gerrit in pipelineTriggers, you should use triggerOnEvents {..} and gettitProjects{...} instead. For more details, you could find them in the document on your jenkins (e.g. http://0.0.0.0:8080/plugin/job-dsl/api-viewer/)
properties {
pipelineTriggers {
triggers {
gerritTrigger {
gerritProjects {
gerritProject {
compareType('PLAIN')
pattern('**My/Git/Repo')
branches {
branch {
compareType('PLAIN')
pattern('master')
}
}
}
}
triggerOnEvents {
changeMerged()
}
}
}
}

JobDSL custom config file

I'm trying to setup a jenkins job with custom config file, original xml looks as follows (the relevant part):
<buildWrappers>
<org.jenkinsci.plugins.configfiles.buildwrapper.ConfigFileBuildWrapper plugin="config-file-provider#2.11">
<managedFiles>
<org.jenkinsci.plugins.configfiles.buildwrapper.ManagedFile>
<fileId>30de8d2f-621d-4c51-b644-4302b548fd15</fileId>
<targetLocation>./src/</targetLocation>
<variable/>
<replaceTokens>false</replaceTokens>
</org.jenkinsci.plugins.configfiles.buildwrapper.ManagedFile>
</managedFiles>
</org.jenkinsci.plugins.configfiles.buildwrapper.ConfigFileBuildWrapper>
</buildWrappers>
Here's my JobDSL attempt:
job('example') {
configure{
it / 'buildWrappers' << 'org.jenkinsci.plugins.configfiles.buildwrapper.ManagedFile' {
managedFiles {
org.jenkinsci.plugins.configfiles.buildwrapper.ManagedFile{
fileId '30de8d2f-621d-4c51-b644-4302b548fd15'
targetLocation './/src//'
}
}
}
}
}
What am I missing? Thanks!
You can use the built-in DSL: https://jenkinsci.github.io/job-dsl-plugin/#path/job-wrappers-configFiles
The built-in DSL will also resolve the fileId from the file name.
job('example') {
wrappers {
configFiles {
file('myCustomConfigFile') {
targetLocation('src')
}
}
}
}

get the list of source files from existing eclipse project using CDT

i am working on CDT eclipse plug in development, i am trying to get the list of sources files which exist in eclipse project explorer using CDT code using following code ,which results null.
Case1:
IFile[] files2 = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(new URI("file:/"+workingDirectory));
for (IFile file : files2) {
System.out.println("fullpath " +file.getFullPath());
}
Case2:
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(getProject().getRawLocationURI());
for (IFile file : files) {
System.out.println("fullpath " +file.getFullPath());
}
Case3:
IFile[] files3 = ResourceLookup.findFilesByName(getProject().getFullPath(),ResourcesPlugin.getWorkspace().getRoot().getProjects(),false);
for (IFile file : files3) {
System.out.println("fullpath " +file.getFullPath());
}
Case4:
IFolder srcFolder = project.getFolder("src");
Case 1 ,2,3 giving me output null, where i am expecting list of files;
in Case 4: i am getting the list of "helloworld/src" files, but i am expecting to get the files from the existing project mean main root ,ex:"helloworld"
please suggest me on this.
You can either walk through the worspace resources tree using IResourceVisitor - or you can walk through CDT model:
private void findSourceFiles(final IProject project) {
final ICProject cproject = CoreModel.getDefault().create(project);
if (cproject != null) {
try {
cproject.accept(new ICElementVisitor() {
#Override
public boolean visit(final ICElement element) throws CoreException {
if (element.getElementType() == ICElement.C_UNIT) {
ITranslationUnit unit = (ITranslationUnit) element;
if (unit.isSourceUnit()) {
System.out.printf("%s, %s, %s\n", element.getElementName(), element.getClass(), element
.getUnderlyingResource().getFullPath());
}
return false;
} else {
return true;
}
}
});
} catch (final CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Note there may be more source files then you actually want (e.g. you may not care system about headers) - you can filter them by checking what the underlying resource is.

Sitecore ASP.NET - manage aliases per domain

I have site running Sitecore 6.3. This site include some subsites (for example www.a.com & www.b.com). I want to ask: is it possible to create separate aliases for this sites (e.g. www.a.com/alias & www.b.com/alias should redirect to different pages). Now if create an alias for site www.a.com it will be also in www.b.com. Any ideas how to manage this?
Thnx.
This is possible. I have already made a Sitecore support ticket for this. I have also worked this out and for me their solution worked fine. (haven't implemented it on the live website yet, because we had no agreement on the costs yet). This is some sample code you might want to look at:
class MultiSiteAliasResolver : AliasResolver
{
public new void Process(HttpRequestArgs args)
{
Assert.ArgumentNotNull(args, "args");
if (!Settings.AliasesActive)
{
Tracer.Warning("Aliases are not active.");
}
else
{
Sitecore.Data.Database database = Sitecore.Context.Database;
if (database == null)
{
Tracer.Warning("There is no context database in AliasResover.");
}
Item aliasItem = getAliasItem(args);
if (aliasItem != null)
{
LinkField linkField = aliasItem.Fields["Linked item"];
if (linkField != null)
{
Item AliasLinkedTo = Sitecore.Context.Database.GetItem(linkField.TargetID);
if (AliasLinkedTo != null)
{
Sitecore.Context.Item = AliasLinkedTo;
}
}
else
{
base.Process(args);
}
}
}
}
/// <summary>
/// Gets the alias item.
/// </summary>
/// <param name="args">The args.</param>
/// <returns></returns>
private Item getAliasItem(HttpRequestArgs args)
{
string websitePath = Sitecore.Context.Site.RootPath.ToLower();
if (args.LocalPath.Length > 1)
{
Item aliasItem = Sitecore.Context.Database.GetItem(websitePath + "/settings/aliassen/" + args.LocalPath);
if (aliasItem != null)
{
return aliasItem;
}
}
return null;
}
}
This class could be inserted in the web.config in place of the AliasResolver. For example:
<processor type="CommandTemplates.Classes.MultiSiteAliasResolver, CommandTemplates" />
I hope this will work for you, good luck!
update: In my example I have a folder under each website node "/settings/aliassen/", that's the location I want the users to set alliases. By the way, also notice that when you change the AliasResolver like this the window that the standard Sitecore Alias button triggers won't have the needed functionality anymore. I haven't had any time to dins a way to make that work, however you could always explain the content managers how to work with your new solution.