Search in sources :

Example 6 with Application

use of com.khartec.waltz.model.application.Application in project waltz by khartec.

the class AuthoritativeSourceService method logRemoval.

private void logRemoval(long id, String username) {
    AuthoritativeSource authSource = getById(id);
    if (authSource == null) {
        return;
    }
    OrganisationalUnit orgUnit = organisationalUnitDao.getById(authSource.parentReference().id());
    DataType dataType = dataTypeDao.getByCode(authSource.dataType());
    Application app = applicationDao.getById(authSource.applicationReference().id());
    if (app != null && dataType != null && orgUnit != null) {
        String msg = String.format("Removed %s as an authoritative source for type: %s for org: %s", app.name(), dataType.name(), orgUnit.name());
        tripleLog(username, orgUnit, dataType, app, msg, Operation.REMOVE);
    }
}
Also used : AuthoritativeSource(com.khartec.waltz.model.authoritativesource.AuthoritativeSource) NonAuthoritativeSource(com.khartec.waltz.model.authoritativesource.NonAuthoritativeSource) DataType(com.khartec.waltz.model.datatype.DataType) OrganisationalUnit(com.khartec.waltz.model.orgunit.OrganisationalUnit) Application(com.khartec.waltz.model.application.Application)

Example 7 with Application

use of com.khartec.waltz.model.application.Application in project waltz by khartec.

the class EntityStatisticGenerator method createIntStatsFor.

private void createIntStatsFor(EntityStatisticDefinition defn, Application[] applications, EntityStatisticValueDao valueDao, int bound, BiFunction<StatisticValueState, Integer, String> outcomeFn) {
    Random rnd = new Random(System.currentTimeMillis());
    List<EntityStatisticValue> values = streamAppRefs(applications).map(appRef -> {
        StatisticValueState state = randomPick(StatisticValueState.values());
        int v = state == StatisticValueState.PROVIDED ? rnd.nextInt(bound) : 0;
        // naughty
        v = rnd.nextInt(bound);
        return ImmutableEntityStatisticValue.builder().entity(appRef).state(state).statisticId(defn.id().get()).current(true).createdAt(LocalDateTime.now()).value(Integer.toString(v)).outcome(outcomeFn.apply(state, v)).provenance(PROVENANCE).build();
    }).collect(toList());
    valueDao.bulkSaveValues(values);
}
Also used : IntStream(java.util.stream.IntStream) EntityHierarchyService(com.khartec.waltz.service.entity_hierarchy.EntityHierarchyService) ImmutableEntityReference(com.khartec.waltz.model.ImmutableEntityReference) BiFunction(java.util.function.BiFunction) OrganisationalUnit(com.khartec.waltz.model.orgunit.OrganisationalUnit) LocalDateTime(java.time.LocalDateTime) OrganisationalUnitDao(com.khartec.waltz.data.orgunit.OrganisationalUnitDao) EntityReference(com.khartec.waltz.model.EntityReference) Random(java.util.Random) EntityKind(com.khartec.waltz.model.EntityKind) ENTITY_STATISTIC_DEFINITION(com.khartec.waltz.schema.tables.EntityStatisticDefinition.ENTITY_STATISTIC_DEFINITION) DIConfiguration(com.khartec.waltz.service.DIConfiguration) Map(java.util.Map) DSLContext(org.jooq.DSLContext) EntityStatisticValueDao(com.khartec.waltz.data.entity_statistic.EntityStatisticValueDao) Application(com.khartec.waltz.model.application.Application) ApplicationDao(com.khartec.waltz.data.application.ApplicationDao) ArrayUtilities.randomPick(com.khartec.waltz.common.ArrayUtilities.randomPick) IOException(java.io.IOException) EntityStatisticDefinitionDao(com.khartec.waltz.data.entity_statistic.EntityStatisticDefinitionDao) com.khartec.waltz.model.entity_statistic(com.khartec.waltz.model.entity_statistic) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) LocalDate(java.time.LocalDate) ENTITY_STATISTIC_VALUE(com.khartec.waltz.schema.tables.EntityStatisticValue.ENTITY_STATISTIC_VALUE) Random(java.util.Random)

Example 8 with Application

use of com.khartec.waltz.model.application.Application in project waltz by khartec.

the class FlowGenerator method main.

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    AuthoritativeSourceDao authSourceDao = ctx.getBean(AuthoritativeSourceDao.class);
    ApplicationService applicationDao = ctx.getBean(ApplicationService.class);
    LogicalFlowService dataFlowDao = ctx.getBean(LogicalFlowService.class);
    OrganisationalUnitService orgUnitDao = ctx.getBean(OrganisationalUnitService.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    List<AuthoritativeSource> authSources = authSourceDao.findByEntityKind(EntityKind.ORG_UNIT);
    List<Application> apps = applicationDao.findAll();
    List<OrganisationalUnit> orgUnits = orgUnitDao.findAll();
    Set<LogicalFlow> expectedFlows = authSources.stream().flatMap(a -> {
        long orgUnitId = a.parentReference().id();
        return IntStream.range(0, rnd.nextInt(40)).mapToObj(i -> ImmutableLogicalFlow.builder().source(a.applicationReference()).target(randomAppPick(apps, orgUnitId)).build());
    }).collect(toSet());
    Set<LogicalFlow> probableFlows = authSources.stream().flatMap(a -> IntStream.range(0, rnd.nextInt(30)).mapToObj(i -> ImmutableLogicalFlow.builder().source(a.applicationReference()).target(randomAppPick(apps, randomPick(orgUnits).id().get())).build())).collect(toSet());
    Set<LogicalFlow> randomFlows = apps.stream().flatMap(a -> IntStream.range(0, rnd.nextInt(5)).mapToObj(i -> {
        EntityReference target = randomAppPick(apps, randomPick(orgUnits).id().get());
        return ImmutableLogicalFlow.builder().source(a.entityReference()).target(target).lastUpdatedBy("admin").build();
    })).collect(toSet());
    dsl.deleteFrom(LOGICAL_FLOW).execute();
    Set<LogicalFlow> all = new HashSet<>();
    all.addAll(randomFlows);
    all.addAll(expectedFlows);
    all.addAll(probableFlows);
    System.out.println("--- saving: " + all.size());
    Set<LogicalFlowRecord> records = SetUtilities.map(all, df -> LogicalFlowDao.TO_RECORD_MAPPER.apply(df, dsl));
    dsl.batchStore(records).execute();
    System.out.println("--- done");
}
Also used : OrganisationalUnitService(com.khartec.waltz.service.orgunit.OrganisationalUnitService) IntStream(java.util.stream.IntStream) AuthoritativeSource(com.khartec.waltz.model.authoritativesource.AuthoritativeSource) SetUtilities(com.khartec.waltz.common.SetUtilities) OrganisationalUnit(com.khartec.waltz.model.orgunit.OrganisationalUnit) EntityReference(com.khartec.waltz.model.EntityReference) Random(java.util.Random) LogicalFlow(com.khartec.waltz.model.logical_flow.LogicalFlow) EntityKind(com.khartec.waltz.model.EntityKind) HashSet(java.util.HashSet) ImmutableLogicalFlow(com.khartec.waltz.model.logical_flow.ImmutableLogicalFlow) DIConfiguration(com.khartec.waltz.service.DIConfiguration) OrganisationalUnitService(com.khartec.waltz.service.orgunit.OrganisationalUnitService) LogicalFlowDao(com.khartec.waltz.data.logical_flow.LogicalFlowDao) DSLContext(org.jooq.DSLContext) ApplicationService(com.khartec.waltz.service.application.ApplicationService) LogicalFlowRecord(com.khartec.waltz.schema.tables.records.LogicalFlowRecord) Collectors.toSet(java.util.stream.Collectors.toSet) LOGICAL_FLOW(com.khartec.waltz.schema.tables.LogicalFlow.LOGICAL_FLOW) Application(com.khartec.waltz.model.application.Application) LogicalFlowService(com.khartec.waltz.service.logical_flow.LogicalFlowService) Set(java.util.Set) AuthoritativeSourceDao(com.khartec.waltz.data.authoritative_source.AuthoritativeSourceDao) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ListUtilities.randomPick(com.khartec.waltz.common.ListUtilities.randomPick) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) LogicalFlowRecord(com.khartec.waltz.schema.tables.records.LogicalFlowRecord) LogicalFlowService(com.khartec.waltz.service.logical_flow.LogicalFlowService) AuthoritativeSourceDao(com.khartec.waltz.data.authoritative_source.AuthoritativeSourceDao) DSLContext(org.jooq.DSLContext) AuthoritativeSource(com.khartec.waltz.model.authoritativesource.AuthoritativeSource) OrganisationalUnit(com.khartec.waltz.model.orgunit.OrganisationalUnit) LogicalFlow(com.khartec.waltz.model.logical_flow.LogicalFlow) ImmutableLogicalFlow(com.khartec.waltz.model.logical_flow.ImmutableLogicalFlow) EntityReference(com.khartec.waltz.model.EntityReference) Application(com.khartec.waltz.model.application.Application) ApplicationService(com.khartec.waltz.service.application.ApplicationService) HashSet(java.util.HashSet)

Example 9 with Application

use of com.khartec.waltz.model.application.Application in project waltz by khartec.

the class AppGroupService method removeApplication.

public List<EntityReference> removeApplication(String userId, long groupId, long applicationId) throws InsufficientPrivelegeException {
    verifyUserCanUpdateGroup(userId, groupId);
    appGroupEntryDao.removeApplication(groupId, applicationId);
    Application app = applicationDao.getById(applicationId);
    audit(groupId, userId, String.format("Removed application %s from group", app != null ? app.name() : applicationId), EntityKind.APPLICATION, Operation.REMOVE);
    return appGroupEntryDao.getEntriesForGroup(groupId);
}
Also used : Application(com.khartec.waltz.model.application.Application)

Example 10 with Application

use of com.khartec.waltz.model.application.Application in project waltz by khartec.

the class AppViewService method getAppView.

public AppView getAppView(long id) {
    EntityReference ref = ImmutableEntityReference.builder().kind(EntityKind.APPLICATION).id(id).build();
    Future<Application> application = dbExecutorPool.submit(() -> applicationService.getById(id));
    Future<OrganisationalUnit> orgUnit = dbExecutorPool.submit(() -> organisationalUnitService.getByAppId(id));
    Future<List<String>> tags = dbExecutorPool.submit(() -> entityTagService.findTagsForEntityReference(mkRef(EntityKind.APPLICATION, id)));
    Future<List<String>> aliases = dbExecutorPool.submit(() -> entityAliasService.findAliasesForEntityReference(ref));
    Future<ComplexityRating> complexity = dbExecutorPool.submit(() -> complexityRatingService.getForApp(id));
    return Unchecked.supplier(() -> ImmutableAppView.builder().app(application.get()).organisationalUnit(orgUnit.get()).tags(tags.get()).aliases(aliases.get()).complexity(complexity.get()).build()).get();
}
Also used : ImmutableEntityReference(com.khartec.waltz.model.ImmutableEntityReference) EntityReference(com.khartec.waltz.model.EntityReference) List(java.util.List) ComplexityRating(com.khartec.waltz.model.complexity.ComplexityRating) OrganisationalUnit(com.khartec.waltz.model.orgunit.OrganisationalUnit) Application(com.khartec.waltz.model.application.Application)

Aggregations

Application (com.khartec.waltz.model.application.Application)17 OrganisationalUnit (com.khartec.waltz.model.orgunit.OrganisationalUnit)8 DSLContext (org.jooq.DSLContext)8 EntityKind (com.khartec.waltz.model.EntityKind)7 EntityReference (com.khartec.waltz.model.EntityReference)6 List (java.util.List)6 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)6 ApplicationDao (com.khartec.waltz.data.application.ApplicationDao)4 AuthoritativeSource (com.khartec.waltz.model.authoritativesource.AuthoritativeSource)4 DataType (com.khartec.waltz.model.datatype.DataType)4 DIConfiguration (com.khartec.waltz.service.DIConfiguration)4 ApplicationService (com.khartec.waltz.service.application.ApplicationService)4 Collectors (java.util.stream.Collectors)4 Collectors.toList (java.util.stream.Collectors.toList)4 AuthoritativeSourceDao (com.khartec.waltz.data.authoritative_source.AuthoritativeSourceDao)3 LogicalFlowDao (com.khartec.waltz.data.logical_flow.LogicalFlowDao)3 ImmutableEntityReference (com.khartec.waltz.model.ImmutableEntityReference)3 EntitySearchOptions (com.khartec.waltz.model.entity_search.EntitySearchOptions)3 LogicalFlow (com.khartec.waltz.model.logical_flow.LogicalFlow)3 IntStream (java.util.stream.IntStream)3