diff --git a/administration/scava-administration/src/app/layout/project/components/create-project/create-project.component.html b/administration/scava-administration/src/app/layout/project/components/create-project/create-project.component.html index f1b219fe9..a8f384f18 100755 --- a/administration/scava-administration/src/app/layout/project/components/create-project/create-project.component.html +++ b/administration/scava-administration/src/app/layout/project/components/create-project/create-project.component.html @@ -313,7 +313,7 @@

Register project

formControlName="description">
- + diff --git a/administration/scava-administration/src/app/layout/project/components/edit-project/add-connector/add-connector-dialog.component.html b/administration/scava-administration/src/app/layout/project/components/edit-project/add-connector/add-connector-dialog.component.html new file mode 100644 index 000000000..09e1287b6 --- /dev/null +++ b/administration/scava-administration/src/app/layout/project/components/edit-project/add-connector/add-connector-dialog.component.html @@ -0,0 +1,30 @@ +
+ + + +
\ No newline at end of file diff --git a/administration/scava-administration/src/app/layout/project/components/edit-project/add-connector/add-connector-dialog.component.ts b/administration/scava-administration/src/app/layout/project/components/edit-project/add-connector/add-connector-dialog.component.ts new file mode 100644 index 000000000..045248e8d --- /dev/null +++ b/administration/scava-administration/src/app/layout/project/components/edit-project/add-connector/add-connector-dialog.component.ts @@ -0,0 +1,46 @@ +import { Component, OnInit } from '@angular/core'; +import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; +import { VersionControlSystems } from '../../create-project/version-control-system.model'; +import { Project } from '../../../project.model'; + +@Component({ + selector: 'app-add-connector', + templateUrl: './add-connector-dialog.component.html' +}) +export class ConnectorMgmtAddDialogComponent implements OnInit { + + public isSaving: boolean; + public gitRepository: any; + constructor( + public activeModal: NgbActiveModal + ) { } + + ngOnInit() { + this.isSaving = true; + this.gitRepository = new Object(); + this.gitRepository._id = null; + } + + clear() { + this.activeModal.dismiss('cancel'); + } + + save(sourceInfo: string, project: Project) { + this.isSaving = true; + switch (sourceInfo) { + case "vcs": + project.vcsRepositories.push(this.gitRepository); + break; + case "bts": + project.bugTrackingSystems.push(); + break; + case "cc": + project.communicationChannels.push(); + break; + default: + break; + } + this.activeModal.dismiss(true); + } + +} diff --git a/administration/scava-administration/src/app/layout/project/components/edit-project/delete-connector/delete-connector-dialog.component.html b/administration/scava-administration/src/app/layout/project/components/edit-project/delete-connector/delete-connector-dialog.component.html new file mode 100644 index 000000000..5643db4c2 --- /dev/null +++ b/administration/scava-administration/src/app/layout/project/components/edit-project/delete-connector/delete-connector-dialog.component.html @@ -0,0 +1,17 @@ +
+ + + +
diff --git a/administration/scava-administration/src/app/layout/project/components/edit-project/delete-connector/delete-connector-dialog.component.ts b/administration/scava-administration/src/app/layout/project/components/edit-project/delete-connector/delete-connector-dialog.component.ts new file mode 100644 index 000000000..f5cda72bd --- /dev/null +++ b/administration/scava-administration/src/app/layout/project/components/edit-project/delete-connector/delete-connector-dialog.component.ts @@ -0,0 +1,41 @@ +import { Component, OnInit } from '@angular/core'; +import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; +import { Project } from '../../../project.model'; + +@Component({ + selector: 'app-delete-connector', + templateUrl: './delete-connector-dialog.component.html' +}) +export class ConnectorMgmtDeleteDialogComponent implements OnInit { + + projectId: string; + + constructor( + public activeModal: NgbActiveModal + ) { } + + ngOnInit() { + } + + clear() { + this.activeModal.dismiss('cancel'); + } + + confirmDelete(sourceInfo: string, target: number, project: Project) { + switch (sourceInfo) { + case "vcs": + project.vcsRepositories.splice(target, 1); + break; + case "bts": + project.bugTrackingSystems.splice(target, 1); + break; + case "cc": + project.communicationChannels.splice(target, 1); + break; + default: + break; + } + this.activeModal.dismiss(true); + } + +} diff --git a/administration/scava-administration/src/app/layout/project/components/edit-project/edit-project.component.html b/administration/scava-administration/src/app/layout/project/components/edit-project/edit-project.component.html index a3bfd1814..8089fad9a 100755 --- a/administration/scava-administration/src/app/layout/project/components/edit-project/edit-project.component.html +++ b/administration/scava-administration/src/app/layout/project/components/edit-project/edit-project.component.html @@ -95,10 +95,20 @@

Edit Project {{project?.shortName}}

- + - + + + - + - + + + - + - + + +
VCS Repositories + VCS Repositories + +
Version Control System {{i + 1}}
+ Version Control System {{i + 1}} : {{vcs._type.split(".")[vcs._type.split(".").length-1]}} + + + +
    Url: @@ -113,10 +123,20 @@

Edit Project {{project?.shortName}}

Bug Tracking Systems + Bug Tracking Systems + +
Bug Tracking System {{i + 1}}
+ Bug Tracking System {{i + 1}} : {{bts?._type.split(".")[bts?._type.split(".").length-1]}} + + + +
    Url: @@ -173,10 +193,20 @@

Edit Project {{project?.shortName}}

Communication Channels + Communication Channels + +
Communication Channel {{i + 1}}
+ Communication Channel {{i + 1}} : {{cc?._type.split(".")[cc?._type.split(".").length-1]}} + + + +
    Url: diff --git a/administration/scava-administration/src/app/layout/project/components/edit-project/edit-project.component.ts b/administration/scava-administration/src/app/layout/project/components/edit-project/edit-project.component.ts index 9161f05ab..8d45c5a09 100755 --- a/administration/scava-administration/src/app/layout/project/components/edit-project/edit-project.component.ts +++ b/administration/scava-administration/src/app/layout/project/components/edit-project/edit-project.component.ts @@ -4,6 +4,9 @@ import { ListProjectService } from '../../../../shared/services/project-service/ import { RoleAuthorities } from '../../../../shared/services/authentication/role-authorities'; import { Project } from '../../project.model'; import { EditProjectService } from '../../../../shared/services/project-service/edit-project.service'; +import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; +import { ConnectorMgmtDeleteDialogComponent } from './delete-connector/delete-connector-dialog.component'; +import { ConnectorMgmtAddDialogComponent } from './add-connector/add-connector-dialog.component'; @Component({ @@ -20,6 +23,7 @@ export class EditProjectComponent implements OnInit { private route: ActivatedRoute, private listProjectService: ListProjectService, private editProjectService: EditProjectService, + public modalService: NgbModal, public roleAuthorities: RoleAuthorities, private router: Router ) { @@ -55,7 +59,19 @@ export class EditProjectComponent implements OnInit { } ) this.previousState(); - console.log(this.project) + } + + addConnector(sourceInfo: string) { + const modalRef = this.modalService.open(ConnectorMgmtAddDialogComponent, { size: 'lg', backdrop: 'static' }); + modalRef.componentInstance.project = this.project; + modalRef.componentInstance.sourceInfo = sourceInfo; + } + + removeConnector(sourceInfo: string, target: number) { + const modalRef = this.modalService.open(ConnectorMgmtDeleteDialogComponent, { size: 'lg', backdrop: 'static' }); + modalRef.componentInstance.project = this.project; + modalRef.componentInstance.sourceInfo = sourceInfo; + modalRef.componentInstance.target = target; } previousState() { diff --git a/administration/scava-administration/src/app/layout/project/project.module.ts b/administration/scava-administration/src/app/layout/project/project.module.ts index 7115a18e5..b3c35b8c6 100755 --- a/administration/scava-administration/src/app/layout/project/project.module.ts +++ b/administration/scava-administration/src/app/layout/project/project.module.ts @@ -30,6 +30,8 @@ import { EditProjectComponent } from './components/edit-project/edit-project.com import { CdkTableModule } from '@angular/cdk/table'; import { CdkTreeModule } from '@angular/cdk/tree'; import { ProjectMgmtDeleteDialogComponent } from './components/delete-project/delete-project-dialog.component'; +import { ConnectorMgmtDeleteDialogComponent } from './components/edit-project/delete-connector/delete-connector-dialog.component'; +import { ConnectorMgmtAddDialogComponent } from './components/edit-project/add-connector/add-connector-dialog.component'; @NgModule({ imports: [ @@ -89,12 +91,16 @@ import { ProjectMgmtDeleteDialogComponent } from './components/delete-project/de AnalysisTaskMgmtDeleteDialogComponent, MetricProvidersMgmtInfoDialogComponent, EditProjectComponent, - ProjectMgmtDeleteDialogComponent + ProjectMgmtDeleteDialogComponent, + ConnectorMgmtDeleteDialogComponent, + ConnectorMgmtAddDialogComponent ], entryComponents: [ AnalysisTaskMgmtDeleteDialogComponent, MetricProvidersMgmtInfoDialogComponent, - ProjectMgmtDeleteDialogComponent + ProjectMgmtDeleteDialogComponent, + ConnectorMgmtDeleteDialogComponent, + ConnectorMgmtAddDialogComponent ], providers: [ NgbModal, diff --git a/metric-platform/platform/org.eclipse.scava.platform.client.api/src/org/eclipse/scava/platform/client/api/ProjectCreationResource.java b/metric-platform/platform/org.eclipse.scava.platform.client.api/src/org/eclipse/scava/platform/client/api/ProjectCreationResource.java index 54665b21e..ea998f11b 100644 --- a/metric-platform/platform/org.eclipse.scava.platform.client.api/src/org/eclipse/scava/platform/client/api/ProjectCreationResource.java +++ b/metric-platform/platform/org.eclipse.scava.platform.client.api/src/org/eclipse/scava/platform/client/api/ProjectCreationResource.java @@ -59,9 +59,9 @@ public static void main(String[] args) throws Exception { for (JsonNode vcs : (ArrayNode)json.get("vcsRepositories")) { VcsRepository repo = null; - if (vcs.get("type").asText().equals("git")) { + if (vcs.get("type").asText().equals("svn")) { repo = new SvnRepository(); - } else if (vcs.get("type").asText().equals("svn")) { + } else if (vcs.get("type").asText().equals("git")) { repo = new GitRepository(); } repo.setName(vcs.get("name").asText()); diff --git a/metric-platform/platform/org.eclipse.scava.platform.client.api/src/org/eclipse/scava/platform/client/api/ProjectEditionResource.java b/metric-platform/platform/org.eclipse.scava.platform.client.api/src/org/eclipse/scava/platform/client/api/ProjectEditionResource.java index 10fab6de9..30d08422b 100644 --- a/metric-platform/platform/org.eclipse.scava.platform.client.api/src/org/eclipse/scava/platform/client/api/ProjectEditionResource.java +++ b/metric-platform/platform/org.eclipse.scava.platform.client.api/src/org/eclipse/scava/platform/client/api/ProjectEditionResource.java @@ -10,6 +10,8 @@ package org.eclipse.scava.platform.client.api; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import org.eclipse.scava.platform.Platform; import org.eclipse.scava.repository.model.BugTrackingSystem; @@ -20,12 +22,15 @@ import org.eclipse.scava.repository.model.bts.bugzilla.Bugzilla; import org.eclipse.scava.repository.model.cc.forum.Forum; import org.eclipse.scava.repository.model.cc.sympa.SympaMailingList; +import org.eclipse.scava.repository.model.documentation.gitbased.DocumentationGitBased; import org.eclipse.scava.repository.model.eclipse.EclipseProject; import org.eclipse.scava.repository.model.github.GitHubBugTracker; import org.eclipse.scava.repository.model.github.GitHubRepository; import org.eclipse.scava.repository.model.gitlab.GitLabRepository; import org.eclipse.scava.repository.model.gitlab.GitLabTracker; import org.eclipse.scava.repository.model.jira.JiraBugTrackingSystem; +import org.eclipse.scava.repository.model.vcs.git.GitRepository; +import org.eclipse.scava.repository.model.vcs.svn.SvnRepository; import org.restlet.data.MediaType; import org.restlet.data.Status; import org.restlet.representation.Representation; @@ -78,6 +83,9 @@ public Representation editProject(Representation entity) { } } + /* + * import generic project + */ private void importProject(JsonNode json, Project project) { if (isValidKey(json, "name")) project.setName(json.get("name").asText()); @@ -86,47 +94,187 @@ private void importProject(JsonNode json, Project project) { if (isValidKey(json, "homePage")) project.setHomePage(json.get("homePage").asText()); - int i = 0; - for (JsonNode vcs : (ArrayNode) json.get("vcsRepositories")) { - VcsRepository repo = project.getVcsRepositories().get(i); - if (isValidKey(vcs, "url")) - repo.setUrl(vcs.get("url").asText()); - i++; +// int i = 0; +// for (JsonNode vcs : (ArrayNode) json.get("vcsRepositories")) { +// VcsRepository repo = project.getVcsRepositories().get(i); +// if (isValidKey(vcs, "url")) +// repo.setUrl(vcs.get("url").asText()); +// i++; +// } + + // Delete vcs elements + List tempVcsRepo = new ArrayList(); + for (VcsRepository repo : project.getVcsRepositories()) { + boolean exist = false; + for (JsonNode vcsJson : (ArrayNode) json.get("vcsRepositories")) { + if (repo.getId().equals(vcsJson.get("_id").asText())) { + exist = true; + break; + } + } + if (!exist) { + tempVcsRepo.add(repo); + } + } + project.getVcsRepositories().removeAll(tempVcsRepo); + + // Add & update vcs elements + for (JsonNode vcsJson : (ArrayNode) json.get("vcsRepositories")) { + boolean exist = false; + for (VcsRepository repo : project.getVcsRepositories()) { + if (repo.getId().equals(vcsJson.get("_id").asText()) ) { + repo.setUrl(vcsJson.get("url").asText()); + exist = true; + break; + } + } + if(!exist) { + VcsRepository repo = null; + switch (vcsJson.get("_type").asText()) { + case "org.eclipse.scava.repository.model.vcs.git.GitRepository": + repo = new GitRepository(); + repo.setUrl(vcsJson.get("url").asText()); + break; + case "org.eclipse.scava.repository.model.documentation.gitbased.GitRepository": + repo = new DocumentationGitBased(); + repo.setUrl(vcsJson.get("url").asText()); + break; + case "org.eclipse.scava.repository.model.vcs.svn.SvnRepository": + repo = new SvnRepository(); + repo.setUrl(vcsJson.get("url").asText()); + break; + default: + break; + } + project.getVcsRepositories().add(repo); + } + } + +// int j = 0; +// for (JsonNode bts : (ArrayNode) json.get("bugTrackingSystems")) { +// BugTrackingSystem buggy = project.getBugTrackingSystems().get(j); +// if (isValidKey(bts, "url")) +// buggy.setUrl(bts.get("url").asText()); +// if (isValidKey(bts, "login")) +// ((JiraBugTrackingSystem) buggy).setLogin(bts.get("login").asText()); +// if (isValidKey(bts, "password")) +// ((JiraBugTrackingSystem) buggy).setPassword(bts.get("password").asText()); +// if (isValidKey(bts, "project")) +// ((JiraBugTrackingSystem) buggy).setProject(bts.get("project").asText()); +// j++; +// } + + // Delete bts elements + List tempBtsRepo = new ArrayList(); + for (BugTrackingSystem buggy : project.getBugTrackingSystems()) { + boolean exist = false; + for (JsonNode btsJson : (ArrayNode) json.get("bugTrackingSystems")) { + if (buggy.getId().equals(btsJson.get("_id").asText())) { + exist = true; + break; + } + } + if (!exist) { + tempBtsRepo.add(buggy); + } } + project.getBugTrackingSystems().removeAll(tempBtsRepo); - int j = 0; - for (JsonNode bts : (ArrayNode) json.get("bugTrackingSystems")) { - BugTrackingSystem buggy = project.getBugTrackingSystems().get(j); - if (isValidKey(bts, "url")) - buggy.setUrl(bts.get("url").asText()); - if (isValidKey(bts, "login")) - ((JiraBugTrackingSystem) buggy).setLogin(bts.get("login").asText()); - if (isValidKey(bts, "password")) - ((JiraBugTrackingSystem) buggy).setPassword(bts.get("password").asText()); - if (isValidKey(bts, "project")) - ((JiraBugTrackingSystem) buggy).setProject(bts.get("project").asText()); - j++; + // Add & update bts elements + for (JsonNode btsJson : (ArrayNode) json.get("bugTrackingSystems")) { + boolean exist = false; + for (BugTrackingSystem buggy : project.getBugTrackingSystems()) { + if (buggy.getId().equals(btsJson.get("_id").asText())) { + buggy.setUrl(btsJson.get("url").asText()); + ((JiraBugTrackingSystem) buggy).setLogin(btsJson.get("login").asText()); + ((JiraBugTrackingSystem) buggy).setPassword(btsJson.get("password").asText()); + ((JiraBugTrackingSystem) buggy).setProject(btsJson.get("project").asText()); + exist = true; + break; + } + } + if (!exist) { + BugTrackingSystem buggy = null; + if (btsJson.get("_type").asText().equals("org.eclipse.scava.repository.model.jira.BugTrackingSystem")) { + buggy = new JiraBugTrackingSystem(); + buggy.setUrl(btsJson.get("url").asText()); + ((JiraBugTrackingSystem) buggy).setLogin(btsJson.get("login").asText()); + ((JiraBugTrackingSystem) buggy).setPassword(btsJson.get("password").asText()); + ((JiraBugTrackingSystem) buggy).setProject(btsJson.get("project").asText()); + } + project.getBugTrackingSystems().add(buggy); + } } - int k = 0; - for (JsonNode cc : (ArrayNode) json.get("communicationChannels")) { - CommunicationChannel comunication = project.getCommunicationChannels().get(k); - if (isValidKey(cc, "url")) - comunication.setUrl(cc.get("url").asText()); - if (isValidKey(cc, "MailingListName")) - ((SympaMailingList) comunication).setMailingListName(cc.get("MailingListName").asText()); - if (isValidKey(cc, "MailingListDescription")) - ((SympaMailingList) comunication).setMailingListDescription(cc.get("MailingListDescription").asText()); - if (isValidKey(cc, "compressedFileExtension")) - ((SympaMailingList) comunication).setCompressedFileExtension(cc.get("compressedFileExtension").asText()); - if (isValidKey(cc, "username")) - ((SympaMailingList) comunication).setUsername(cc.get("username").asText()); - if (isValidKey(cc, "password")) - ((SympaMailingList) comunication).setPassword(cc.get("password").asText()); - k++; +// int k = 0; +// for (JsonNode cc : (ArrayNode) json.get("communicationChannels")) { +// CommunicationChannel comunication = project.getCommunicationChannels().get(k); +// if (isValidKey(cc, "url")) +// comunication.setUrl(cc.get("url").asText()); +// if (isValidKey(cc, "MailingListName")) +// ((SympaMailingList) comunication).setMailingListName(cc.get("MailingListName").asText()); +// if (isValidKey(cc, "MailingListDescription")) +// ((SympaMailingList) comunication).setMailingListDescription(cc.get("MailingListDescription").asText()); +// if (isValidKey(cc, "compressedFileExtension")) +// ((SympaMailingList) comunication).setCompressedFileExtension(cc.get("compressedFileExtension").asText()); +// if (isValidKey(cc, "username")) +// ((SympaMailingList) comunication).setUsername(cc.get("username").asText()); +// if (isValidKey(cc, "password")) +// ((SympaMailingList) comunication).setPassword(cc.get("password").asText()); +// k++; +// } + + // Delete communication channel elements + List tempCcRepo = new ArrayList(); + for (CommunicationChannel communication : project.getCommunicationChannels()) { + boolean exist = false; + for (JsonNode ccJson : (ArrayNode) json.get("communicationChannels")) { + if (communication.getId().equals(ccJson.get("_id").asText())) { + exist = true; + break; + } + } + if (!exist) { + tempCcRepo.add(communication); + } } + project.getCommunicationChannels().removeAll(tempCcRepo); + + // Add & update communication channel elements + for (JsonNode ccJson : (ArrayNode) json.get("communicationChannels")) { + boolean exist = false; + for (CommunicationChannel communication : project.getCommunicationChannels()) { + if (communication.getId().equals(ccJson.get("_id").asText())) { + communication.setUrl(ccJson.get("url").asText()); + ((SympaMailingList) communication).setMailingListName(ccJson.get("MailingListName").asText()); + ((SympaMailingList) communication).setMailingListDescription(ccJson.get("MailingListDescription").asText()); + ((SympaMailingList) communication).setCompressedFileExtension(ccJson.get("compressedFileExtension").asText()); + ((SympaMailingList) communication).setUsername(ccJson.get("username").asText()); + ((SympaMailingList) communication).setPassword(ccJson.get("password").asText()); + exist = true; + break; + } + } + if (!exist) { + CommunicationChannel communication = null; + if (ccJson.get("_type").asText().equals("org.eclipse.scava.repository.model.cc.sympa.CommunicationChannel")) { + communication = new SympaMailingList(); + communication.setUrl(ccJson.get("url").asText()); + ((SympaMailingList) communication).setMailingListName(ccJson.get("MailingListName").asText()); + ((SympaMailingList) communication).setMailingListDescription(ccJson.get("MailingListDescription").asText()); + ((SympaMailingList) communication).setCompressedFileExtension(ccJson.get("compressedFileExtension").asText()); + ((SympaMailingList) communication).setUsername(ccJson.get("username").asText()); + ((SympaMailingList) communication).setPassword(ccJson.get("password").asText()); + } + project.getCommunicationChannels().add(communication); + } + } + } - + + /* + * import GitHub project + */ private void importGithubProject(JsonNode json, Project project) { GitHubRepository githubRepository = (GitHubRepository) project; @@ -149,45 +297,128 @@ private void importGithubProject(JsonNode json, Project project) { if (isValidKey(json, "clone_url")) githubRepository.setClone_url(json.get("clone_url").asText()); - int i = 0; - for (JsonNode vcs : (ArrayNode) json.get("vcsRepositories")) { - VcsRepository repo = githubRepository.getVcsRepositories().get(i); - if (isValidKey(vcs, "url")) - repo.setUrl(vcs.get("url").asText()); - i++; +// int i = 0; +// for (JsonNode vcs : (ArrayNode) json.get("vcsRepositories")) { +// VcsRepository repo = githubRepository.getVcsRepositories().get(i); +// if (isValidKey(vcs, "url")) +// repo.setUrl(vcs.get("url").asText()); +// i++; +// } + + // Delete vcs elements + List tempVcsRepo = new ArrayList(); + for (VcsRepository repo : githubRepository.getVcsRepositories()) { + boolean exist = false; + for (JsonNode vcsJson : (ArrayNode) json.get("vcsRepositories")) { + if (repo.getId().equals(vcsJson.get("_id").asText())) { + exist = true; + break; + } + } + if (!exist) { + tempVcsRepo.add(repo); + } } + githubRepository.getVcsRepositories().removeAll(tempVcsRepo); - int j = 0; - for (JsonNode bts : (ArrayNode) json.get("bugTrackingSystems")) { - BugTrackingSystem buggy = githubRepository.getBugTrackingSystems().get(j); - if (isValidKey(bts, "url")) { - buggy.setUrl(bts.get("url").asText()); - } - if (isValidKey(bts, "token")) { - String token = bts.get("token").asText(); - String owner = githubRepository.getFull_name().split("/")[0]; - String repo = githubRepository.getFull_name().split("/")[1]; - ((GitHubBugTracker) buggy).setProject(token, owner, repo); - } - if (isValidKey(bts, "login")) - ((JiraBugTrackingSystem) buggy).setLogin(bts.get("login").asText()); - if (isValidKey(bts, "password")) - ((JiraBugTrackingSystem) buggy).setPassword(bts.get("password").asText()); - if (isValidKey(bts, "project")) - ((JiraBugTrackingSystem) buggy).setProject(bts.get("project").asText()); - j++; + // Add & update vcs elements + for (JsonNode vcsJson : (ArrayNode) json.get("vcsRepositories")) { + boolean exist = false; + for (VcsRepository repo : githubRepository.getVcsRepositories()) { + if (repo.getId().equals(vcsJson.get("_id").asText()) ) { + repo.setUrl(vcsJson.get("url").asText()); + exist = true; + break; + } + } + if(!exist) { + VcsRepository repo = null; + if (vcsJson.get("_type").asText().equals("org.eclipse.scava.repository.model.vcs.git.GitRepository")) { + repo = new GitRepository(); + repo.setUrl(vcsJson.get("url").asText()); + } + githubRepository.getVcsRepositories().add(repo); + } } - int k = 0; - for (JsonNode cc : (ArrayNode) json.get("communicationChannels")) { - CommunicationChannel comunication = githubRepository.getCommunicationChannels().get(k); - - if (isValidKey(cc, "url")) - comunication.setUrl(cc.get("url").asText()); - k++; - } +// int j = 0; +// for (JsonNode bts : (ArrayNode) json.get("bugTrackingSystems")) { +// BugTrackingSystem buggy = githubRepository.getBugTrackingSystems().get(j); +// if (isValidKey(bts, "url")) { +// buggy.setUrl(bts.get("url").asText()); +// } +// if (isValidKey(bts, "token")) { +// String token = bts.get("token").asText(); +// String owner = githubRepository.getFull_name().split("/")[0]; +// String repo = githubRepository.getFull_name().split("/")[1]; +// ((GitHubBugTracker) buggy).setProject(token, owner, repo); +// } +// if (isValidKey(bts, "login")) +// ((JiraBugTrackingSystem) buggy).setLogin(bts.get("login").asText()); +// if (isValidKey(bts, "password")) +// ((JiraBugTrackingSystem) buggy).setPassword(bts.get("password").asText()); +// if (isValidKey(bts, "project")) +// ((JiraBugTrackingSystem) buggy).setProject(bts.get("project").asText()); +// j++; +// } + + // Delete bts elements + List tempBtsRepo = new ArrayList(); + for (BugTrackingSystem buggy : githubRepository.getBugTrackingSystems()) { + boolean exist = false; + for (JsonNode btsJson : (ArrayNode) json.get("bugTrackingSystems")) { + if (buggy.getId().equals(btsJson.get("_id").asText())) { + exist = true; + break; + } + } + if (!exist) { + tempBtsRepo.add(buggy); + } + } + githubRepository.getBugTrackingSystems().removeAll(tempBtsRepo); + + // Add & update bts elements + for (JsonNode btsJson : (ArrayNode) json.get("bugTrackingSystems")) { + boolean exist = false; + for (BugTrackingSystem buggy : githubRepository.getBugTrackingSystems()) { + if (buggy.getId().equals(btsJson.get("_id").asText())) { + buggy.setUrl(btsJson.get("url").asText()); + String token = btsJson.get("token").asText(); + String owner = githubRepository.getFull_name().split("/")[0]; + String repo = githubRepository.getFull_name().split("/")[1]; + ((GitHubBugTracker) buggy).setProject(token, owner, repo); + exist = true; + break; + } + } + if (!exist) { + BugTrackingSystem buggy = null; + if (btsJson.get("_type").asText().equals("org.eclipse.scava.repository.model.github.GitHubBugTracker")) { + buggy = new GitHubBugTracker(); + buggy.setUrl(btsJson.get("url").asText()); + String token = btsJson.get("token").asText(); + String owner = githubRepository.getFull_name().split("/")[0]; + String repo = githubRepository.getFull_name().split("/")[1]; + ((GitHubBugTracker) buggy).setProject(token, owner, repo); + } + githubRepository.getBugTrackingSystems().add(buggy); + } + } + +// int k = 0; +// for (JsonNode cc : (ArrayNode) json.get("communicationChannels")) { +// CommunicationChannel comunication = githubRepository.getCommunicationChannels().get(k); +// +// if (isValidKey(cc, "url")) +// comunication.setUrl(cc.get("url").asText()); +// k++; +// } } + /* + * import GitLab project + */ private void importGitlabProject(JsonNode json, Project project) { GitLabRepository gitlabRepository = (GitLabRepository) project; @@ -204,34 +435,110 @@ private void importGitlabProject(JsonNode json, Project project) { if (isValidKey(json, "clone_url")) gitlabRepository.setClone_url(json.get("clone_url").asText()); - int i = 0; - for (JsonNode vcs : (ArrayNode) json.get("vcsRepositories")) { - VcsRepository repo = gitlabRepository.getVcsRepositories().get(i); - if (isValidKey(vcs, "url")) - repo.setUrl(vcs.get("url").asText()); - i++; +// int i = 0; +// for (JsonNode vcs : (ArrayNode) json.get("vcsRepositories")) { +// VcsRepository repo = gitlabRepository.getVcsRepositories().get(i); +// if (isValidKey(vcs, "url")) +// repo.setUrl(vcs.get("url").asText()); +// i++; +// } + + // Delete vcs elements + List tempVcsRepo = new ArrayList(); + for (VcsRepository repo : gitlabRepository.getVcsRepositories()) { + boolean exist = false; + for (JsonNode vcsJson : (ArrayNode) json.get("vcsRepositories")) { + if (repo.getId().equals(vcsJson.get("_id").asText())) { + exist = true; + break; + } + } + if (!exist) { + tempVcsRepo.add(repo); + } + } + gitlabRepository.getVcsRepositories().removeAll(tempVcsRepo); + + // Add & update vcs elements + for (JsonNode vcsJson : (ArrayNode) json.get("vcsRepositories")) { + boolean exist = false; + for (VcsRepository repo : gitlabRepository.getVcsRepositories()) { + if (repo.getId().equals(vcsJson.get("_id").asText())) { + repo.setUrl(vcsJson.get("url").asText()); + exist = true; + break; + } + } + if (!exist) { + VcsRepository repo = null; + if (vcsJson.get("_type").asText().equals("org.eclipse.scava.repository.model.vcs.git.GitRepository")) { + repo = new GitRepository(); + repo.setUrl(vcsJson.get("url").asText()); + } + gitlabRepository.getVcsRepositories().add(repo); + } } - int j = 0; - for (JsonNode bts : (ArrayNode) json.get("bugTrackingSystems")) { - BugTrackingSystem buggy = gitlabRepository.getBugTrackingSystems().get(j); - if (isValidKey(bts, "url")) - buggy.setUrl(bts.get("url").asText()); - if (isValidKey(bts, "personal_access_token")) - ((GitLabTracker)buggy).setPersonal_access_token(bts.get("personal_access_token").asText()); - j++; +// int j = 0; +// for (JsonNode bts : (ArrayNode) json.get("bugTrackingSystems")) { +// BugTrackingSystem buggy = gitlabRepository.getBugTrackingSystems().get(j); +// if (isValidKey(bts, "url")) +// buggy.setUrl(bts.get("url").asText()); +// if (isValidKey(bts, "personal_access_token")) +// ((GitLabTracker)buggy).setPersonal_access_token(bts.get("personal_access_token").asText()); +// j++; +// } + + // Delete bts elements + List tempBtsRepo = new ArrayList(); + for (BugTrackingSystem buggy : gitlabRepository.getBugTrackingSystems()) { + boolean exist = false; + for (JsonNode btsJson : (ArrayNode) json.get("bugTrackingSystems")) { + if (buggy.getId().equals(btsJson.get("_id").asText())) { + exist = true; + break; + } + } + if (!exist) { + tempBtsRepo.add(buggy); + } } + gitlabRepository.getBugTrackingSystems().removeAll(tempBtsRepo); - int k = 0; - for (JsonNode cc : (ArrayNode) json.get("communicationChannels")) { - CommunicationChannel comunication = gitlabRepository.getCommunicationChannels().get(k); - if (isValidKey(cc, "url")) - comunication.setUrl(cc.get("url").asText()); - k++; - } + // Add & update bts elements + for (JsonNode btsJson : (ArrayNode) json.get("bugTrackingSystems")) { + boolean exist = false; + for (BugTrackingSystem buggy : gitlabRepository.getBugTrackingSystems()) { + if (buggy.getId().equals(btsJson.get("_id").asText())) { + buggy.setUrl(btsJson.get("url").asText()); + ((GitLabTracker)buggy).setPersonal_access_token(btsJson.get("personal_access_token").asText()); + exist = true; + break; + } + } + if (!exist) { + BugTrackingSystem buggy = null; + if (btsJson.get("_type").asText().equals("org.eclipse.scava.repository.model.gitlab.GitLabTracker")) { + buggy = new GitLabTracker(); + buggy.setUrl(btsJson.get("url").asText()); + ((GitLabTracker)buggy).setPersonal_access_token(btsJson.get("personal_access_token").asText()); + } + gitlabRepository.getBugTrackingSystems().add(buggy); + } + } + +// int k = 0; +// for (JsonNode cc : (ArrayNode) json.get("communicationChannels")) { +// CommunicationChannel comunication = gitlabRepository.getCommunicationChannels().get(k); +// if (isValidKey(cc, "url")) +// comunication.setUrl(cc.get("url").asText()); +// k++; +// } } - + /* + * import Eclipse project + */ private void importEclipseProject(JsonNode json, Project project) { EclipseProject eclipseProject = (EclipseProject) project; @@ -248,47 +555,166 @@ private void importEclipseProject(JsonNode json, Project project) { if (isValidKey(json, "projectplanUrl")) eclipseProject.setProjectplanUrl(json.get("projectplanUrl").asText()); - int i = 0; - for (JsonNode vcs : (ArrayNode) json.get("vcsRepositories")) { - VcsRepository repo = eclipseProject.getVcsRepositories().get(i); - if (isValidKey(vcs, "url")) - repo.setUrl(vcs.get("url").asText()); - if (isValidKey(vcs, "name")) - repo.setUrl(vcs.get("name").asText()); - i++; +// int i = 0; +// for (JsonNode vcs : (ArrayNode) json.get("vcsRepositories")) { +// VcsRepository repo = eclipseProject.getVcsRepositories().get(i); +// if (isValidKey(vcs, "url")) +// repo.setUrl(vcs.get("url").asText()); +// if (isValidKey(vcs, "name")) +// repo.setUrl(vcs.get("name").asText()); +// i++; +// } + + // Delete vcs elements + List tempVcsRepo = new ArrayList(); + for (VcsRepository repo : eclipseProject.getVcsRepositories()) { + boolean exist = false; + for (JsonNode vcsJson : (ArrayNode) json.get("vcsRepositories")) { + if (repo.getId().equals(vcsJson.get("_id").asText())) { + exist = true; + break; + } + } + if (!exist) { + tempVcsRepo.add(repo); + } + } + eclipseProject.getVcsRepositories().removeAll(tempVcsRepo); + + // Add & update vcs elements + for (JsonNode vcsJson : (ArrayNode) json.get("vcsRepositories")) { + boolean exist = false; + for (VcsRepository repo : eclipseProject.getVcsRepositories()) { + if (repo.getId().equals(vcsJson.get("_id").asText())) { + repo.setUrl(vcsJson.get("url").asText()); + repo.setName(vcsJson.get("name").asText()); + exist = true; + break; + } + } + if (!exist) { + VcsRepository repo = null; + if (vcsJson.get("_type").asText().equals("org.eclipse.scava.repository.model.vcs.git.GitRepository")) { + repo = new GitRepository(); + repo.setUrl(vcsJson.get("url").asText()); + repo.setName(vcsJson.get("name").asText()); + } + eclipseProject.getVcsRepositories().add(repo); + } } - int j = 0; - for (JsonNode bts : (ArrayNode) json.get("bugTrackingSystems")) { - BugTrackingSystem buggy = eclipseProject.getBugTrackingSystems().get(j); - if (isValidKey(bts, "url")) - buggy.setUrl(bts.get("url").asText()); - if (isValidKey(bts, "product")) - ((Bugzilla)buggy).setProduct(bts.get("product").asText()); - if (isValidKey(bts, "component")) - ((Bugzilla)buggy).setComponent(bts.get("component").asText()); - if (isValidKey(bts, "cgiQueryProgram")) - ((Bugzilla)buggy).setCgiQueryProgram(bts.get("cgiQueryProgram").asText()); - j++; +// int j = 0; +// for (JsonNode bts : (ArrayNode) json.get("bugTrackingSystems")) { +// BugTrackingSystem buggy = eclipseProject.getBugTrackingSystems().get(j); +// if (isValidKey(bts, "url")) +// buggy.setUrl(bts.get("url").asText()); +// if (isValidKey(bts, "product")) +// ((Bugzilla)buggy).setProduct(bts.get("product").asText()); +// if (isValidKey(bts, "component")) +// ((Bugzilla)buggy).setComponent(bts.get("component").asText()); +// if (isValidKey(bts, "cgiQueryProgram")) +// ((Bugzilla)buggy).setCgiQueryProgram(bts.get("cgiQueryProgram").asText()); +// j++; +// } + + // Delete bts elements + List tempBtsRepo = new ArrayList(); + for (BugTrackingSystem buggy : eclipseProject.getBugTrackingSystems()) { + boolean exist = false; + for (JsonNode btsJson : (ArrayNode) json.get("bugTrackingSystems")) { + if (buggy.getId().equals(btsJson.get("_id").asText())) { + exist = true; + break; + } + } + if (!exist) { + tempBtsRepo.add(buggy); + } } + eclipseProject.getBugTrackingSystems().removeAll(tempBtsRepo); + + // Add & update bts elements + for (JsonNode btsJson : (ArrayNode) json.get("bugTrackingSystems")) { + boolean exist = false; + for (BugTrackingSystem buggy : eclipseProject.getBugTrackingSystems()) { + if (buggy.getId().equals(btsJson.get("_id").asText())) { + buggy.setUrl(btsJson.get("url").asText()); + ((Bugzilla)buggy).setProduct(btsJson.get("product").asText()); + ((Bugzilla)buggy).setComponent(btsJson.get("component").asText()); + ((Bugzilla)buggy).setCgiQueryProgram(btsJson.get("cgiQueryProgram").asText()); + exist = true; + break; + } + } + if (!exist) { + BugTrackingSystem buggy = null; + if (btsJson.get("_type").asText().equals("org.eclipse.scava.repository.model.bts.bugzilla.Bugzilla")) { + buggy = new Bugzilla(); + buggy.setUrl(btsJson.get("url").asText()); + ((Bugzilla)buggy).setProduct(btsJson.get("product").asText()); + ((Bugzilla)buggy).setComponent(btsJson.get("component").asText()); + ((Bugzilla)buggy).setCgiQueryProgram(btsJson.get("cgiQueryProgram").asText()); + } + eclipseProject.getBugTrackingSystems().add(buggy); + } + } + +// int k = 0; +// for (JsonNode cc : (ArrayNode) json.get("communicationChannels")) { +// CommunicationChannel comunication = eclipseProject.getCommunicationChannels().get(k); +// if (isValidKey(cc, "url")) +// comunication.setUrl(cc.get("url").asText()); +// if (isValidKey(cc, "name")) +// ((Forum) comunication).setName(cc.get("name").asText()); +// if (isValidKey(cc, "description")) +// ((Forum) comunication).setDescription(cc.get("description").asText()); +// k++; +// } - int k = 0; - for (JsonNode cc : (ArrayNode) json.get("communicationChannels")) { - CommunicationChannel comunication = eclipseProject.getCommunicationChannels().get(k); - if (isValidKey(cc, "url")) - comunication.setUrl(cc.get("url").asText()); - if (isValidKey(cc, "name")) - ((Forum) comunication).setName(cc.get("name").asText()); - if (isValidKey(cc, "description")) - ((Forum) comunication).setDescription(cc.get("description").asText()); - k++; + // Delete communication channel elements + List tempCcRepo = new ArrayList(); + for (CommunicationChannel communication : eclipseProject.getCommunicationChannels()) { + boolean exist = false; + for (JsonNode ccJson : (ArrayNode) json.get("communicationChannels")) { + if (communication.getId().equals(ccJson.get("_id").asText())) { + exist = true; + break; + } + } + if (!exist) { + tempCcRepo.add(communication); + } + } + eclipseProject.getCommunicationChannels().removeAll(tempCcRepo); + + // Add & update communication channel elements + for (JsonNode ccJson : (ArrayNode) json.get("communicationChannels")) { + boolean exist = false; + for (CommunicationChannel communication : eclipseProject.getCommunicationChannels()) { + if (communication.getId().equals(ccJson.get("_id").asText())) { + communication.setUrl(ccJson.get("url").asText()); + ((Forum) communication).setName(ccJson.get("name").asText()); + ((Forum) communication).setDescription(ccJson.get("description").asText()); + exist = true; + break; + } + } + if (!exist) { + CommunicationChannel communication = null; + if (ccJson.get("_type").asText().equals("org.eclipse.scava.repository.model.cc.forum.Forum")) { + communication = new Forum(); + communication.setUrl(ccJson.get("url").asText()); + ((Forum) communication).setName(ccJson.get("name").asText()); + ((Forum) communication).setDescription(ccJson.get("description").asText()); + } + eclipseProject.getCommunicationChannels().add(communication); + } } } public boolean isValidKey(JsonNode json, String key) { if (json.has(key) && json.get(key).asText() != null && !json.get(key).asText().equals("")) return true; - else - return false; + return false; } }