Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tankchintan/1528301 to your computer and use it in GitHub Desktop.
Save tankchintan/1528301 to your computer and use it in GitHub Desktop.
code to dump depositorystructure into sourcesets and sources tables
Hi Meena..............
//Method to dump depositorystructure into sourcesets and sources tables
public String dumpDepositoryStructureInToSourceSetsAndSources() {
//Get all active depositories
for (Depository depository : depositoryDAO.getAll()) {
int count = 1;
//Get depository categories
for (Depositorycategory depositorycategory : depository.getDepositorycategories()) {
Category category = depositorycategory.getCategory();
//Create sourceset with type "CATEGORY"
List<SourceSet> sourceSets = sourceSetDAO.getByNameAndType(category.getName(), "CATEGORY", true);
//skip the loop if category already exists in DB, this will skip the creation of all the sources & sourcesets existing in the category.
if (sourceSets.isEmpty()) {
continue;
}
//Create Sourceset with Category Details
SourceSet createdCategory = createSourceSet(category.getName(), "CATEGORY");
System.out.println("===================================================");
System.out.println("count= " + count + " category: " + category.getName());
System.out.println("===================================================");
//Create Depository to SourceSet(Category) Mapping
createDepositoryToSourceSet(depository.getId(), createdCategory.getId());
//Create SourceSets and sources for specific category
createSourceSetsAndSourcesFromCategory(category, createdCategory.getId());
count++;
}
}
return SUCCESS;
}
/*
* Dril down into Category to create SourceSets & Sources
*/
private void createSourceSetsAndSourcesFromCategory(Category category, String createdCategoryId) {
//Get all sourcesets mapped to category
for (Categorysourceset categorysourceset : category.getCategorysourcesets()) {
//get the sourceset from categorysourceset
Sourceset oldParentSourceSet = categorysourceset.getSourceset();
//Create Sourceset from the existing Sourceset with type "SOURCESET"
SourceSet createdParentSourceSet = createSourceSet(oldParentSourceSet.getName(), "SOURCESET");
//Create Mapping in between category and newly created sourceset
createSourceSetToSourceSet(createdCategoryId, createdParentSourceSet.getId());
//Get the child sourcesets
Set<Sourceset> childSourcesetList = oldParentSourceSet.getChildSourcesetList();
if (childSourcesetList.isEmpty()) {
/*
* Create sources and sourceset mappings with the newly created sourceset directly
*/
//Get the sources mapped to sourceset
Set<Sourcesetsource> sourceSetSources = oldParentSourceSet.getSourcesetsources();
for (Sourcesetsource sourceSetSource : sourceSetSources) {
/*
* Create new entry in sources table with the existing source details &
* Create sourceset to source mapping
*/
createSourcesAndSourceSetToSource(sourceSetSource.getSource(), createdParentSourceSet.getId());
}
} else {
/*
* create parent and childsourceset mapping and
* create sources and sourceset mappings with the child sourceset
*/
for (Sourceset OldChildSourceSet : childSourcesetList) {
//Create Child Sourceset from the existing Sourceset with type "SOURCESET"
SourceSet createdChildSourceSet = createSourceSet(OldChildSourceSet.getName(), "SOURCESET");
//Create Mapping in between Parent SOurceset and Child sourceset
createSourceSetToSourceSet(createdParentSourceSet.getId(), createdChildSourceSet.getId());
//Get the sources mapped to Child Sourceset
Set<Sourcesetsource> sourceSetSources = OldChildSourceSet.getSourcesetsources();
for (Sourcesetsource sourceSetSource : sourceSetSources) {
/*
* Create new entry in sources table with the existing source details &
* Create child sourceset to source mapping
*/
createSourcesAndSourceSetToSource(sourceSetSource.getSource(), createdChildSourceSet.getId());
}
}
}
}
}
private void createSourcesAndSourceSetToSource(Source oldSource, String createdSourceSetId) {
if (oldSource.getIdList().size() > 1) {
//Need to think about it
} else {
CoreSource coreSource = createSource(oldSource);
createSourceSetToSource(createdSourceSetId, coreSource.getId());
}
}
/*
* To create Depository- Sourceset Mapping
*/
private void createDepositoryToSourceSet(String depositoryId, String sourcesetId) {
DepositoryToSourceSetId depositoryToSourceSetId = new DepositoryToSourceSetId(depositoryId, sourcesetId);
if (depositoryToSourceSetDAO.getById(depositoryToSourceSetId) == null) {
depositoryToSourceSetDAO.create(new DepositoryToSourceSet(depositoryToSourceSetId));
}
}
/*
* To create sourceset
*/
private SourceSet createSourceSet(String name, String type) {
SourceSet sourceSet = new SourceSet(name, type);
sourceSet.setIsActive(true);
sourceSetDAO.create(sourceSet);
return sourceSet;
}
/*
* To create Sourceset- Sourceset Mapping
*/
private void createSourceSetToSourceSet(String parentSourceSetId, String childSourceSetId) {
SourceSetToSourceSetId sourceSetToSourceSetId = new SourceSetToSourceSetId(
parentSourceSetId,
childSourceSetId);
if (sourceSetToSourceSetDAO.getById(sourceSetToSourceSetId) == null) {
sourceSetToSourceSetDAO.create(new SourceSetToSourceSet(sourceSetToSourceSetId));
}
}
/*
* To create Source
*/
private CoreSource createSource(Source oldSource) {
CoreSource coreSource = sourceDAO.getBySourceId(oldSource.getSourceid());
if (coreSource == null) {
coreSource = new CoreSource(oldSource.getSourceid(), oldSource.getUrl());
coreSource.setIsActive(true);
sourceDAO.create(coreSource);
}
return coreSource;
}
/*
* To create Sourceset-Source mapping
*/
private void createSourceSetToSource(String sourceSetId, String sourceId) {
SourceSetToSourceId sourceSetToSourceId = new SourceSetToSourceId(sourceSetId, sourceId);
if (sourceSetToSourceDAO.getById(sourceSetToSourceId) == null) {
sourceSetToSourceDAO.create(new SourceSetToSource(sourceSetToSourceId));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment