use of org.craftercms.studio.api.v1.dal.DependencyEntity in project studio by craftercms.
the class DependencyServiceImpl method createDependencyEntities.
public List<DependencyEntity> createDependencyEntities(String site, String path, Set<String> dependencyPaths, String dependencyType, Set<String> extractedPaths) {
logger.debug("Create dependency entity TO for site: " + site + " path: " + path);
List<DependencyEntity> dependencyEntities = new ArrayList<>();
if (dependencyPaths != null && dependencyPaths.size() > 0) {
for (String file : dependencyPaths) {
DependencyEntity dependencyObj = new DependencyEntity();
dependencyObj.setSite(site);
dependencyObj.setSourcePath(getCleanPath(path));
dependencyObj.setTargetPath(getCleanPath(file));
dependencyObj.setType(dependencyType);
dependencyEntities.add(dependencyObj);
extractedPaths.add(file);
}
}
return dependencyEntities;
}
use of org.craftercms.studio.api.v1.dal.DependencyEntity in project studio by craftercms.
the class DependencyServiceImpl method upsertDependencies.
@Override
public Set<String> upsertDependencies(String site, List<String> paths) throws SiteNotFoundException, ContentNotFoundException, ServiceLayerException {
Set<String> toRet = new HashSet<String>();
List<DependencyEntity> dependencyEntities = new ArrayList<>();
StringBuilder sbPaths = new StringBuilder();
logger.debug("Resolving dependencies for list of paths.");
for (String path : paths) {
sbPaths.append("\n").append(path);
logger.debug("Resolving dependencies for content site: " + site + " path: " + path);
Map<String, Set<String>> dependencies = dependencyResolver.resolve(site, path);
if (dependencies != null) {
logger.debug("Found " + dependencies.size() + " dependencies. " + "Create entities to insert into database.");
for (String type : dependencies.keySet()) {
dependencyEntities.addAll(createDependencyEntities(site, path, dependencies.get(type), type, toRet));
}
}
}
logger.debug("Preparing transaction for database updates.");
DefaultTransactionDefinition defaultTransactionDefinition = new DefaultTransactionDefinition();
defaultTransactionDefinition.setName("upsertDependencies");
String lock = site + ":upsertDependencies";
generalLockService.lock(lock);
logger.debug("Starting transaction.");
TransactionStatus txStatus = transactionManager.getTransaction(defaultTransactionDefinition);
try {
logger.debug("Delete all source dependencies for list of paths site: " + site);
for (String path : paths) {
deleteAllSourceDependencies(site, path);
}
logger.debug("Insert all extracted dependencies entries lof list of paths for site: " + site);
insertDependenciesIntoDatabase(dependencyEntities);
logger.debug("Committing transaction.");
transactionManager.commit(txStatus);
} catch (Exception e) {
logger.debug("Rolling back transaction.", e);
transactionManager.rollback(txStatus);
throw new ServiceLayerException("Failed to upsert dependencies for site: " + site + " paths: " + sbPaths.toString(), e);
} finally {
generalLockService.unlock(lock);
}
return toRet;
}
use of org.craftercms.studio.api.v1.dal.DependencyEntity in project studio by craftercms.
the class DependencyServiceImpl method upsertDependencies.
@Override
public Set<String> upsertDependencies(String site, String path) throws SiteNotFoundException, ContentNotFoundException, ServiceLayerException {
Set<String> toRet = new HashSet<String>();
logger.debug("Resolving dependencies for content site: " + site + " path: " + path);
Map<String, Set<String>> dependencies = dependencyResolver.resolve(site, path);
List<DependencyEntity> dependencyEntities = new ArrayList<>();
if (dependencies != null) {
logger.debug("Found " + dependencies.size() + " dependencies. Create entities to insert into database.");
for (String type : dependencies.keySet()) {
dependencyEntities.addAll(createDependencyEntities(site, path, dependencies.get(type), type, toRet));
}
logger.debug("Preparing transaction for database updates.");
DefaultTransactionDefinition defaultTransactionDefinition = new DefaultTransactionDefinition();
defaultTransactionDefinition.setName("upsertDependencies");
String lock = site + ":upsertDependencies";
generalLockService.lock(lock);
logger.debug("Starting transaction.");
TransactionStatus txStatus = transactionManager.getTransaction(defaultTransactionDefinition);
try {
logger.debug("Delete all source dependencies for site: " + site + " path: " + path);
deleteAllSourceDependencies(site, path);
logger.debug("Insert all extracted dependencies entries for site: " + site + " path: " + path);
insertDependenciesIntoDatabase(dependencyEntities);
logger.debug("Committing transaction.");
transactionManager.commit(txStatus);
} catch (Exception e) {
logger.debug("Rolling back transaction.", e);
transactionManager.rollback(txStatus);
throw new ServiceLayerException("Failed to upsert dependencies for site: " + site + " path: " + path, e);
} finally {
generalLockService.unlock(lock);
}
}
return toRet;
}
Aggregations