Search in sources :

Example 1 with OrganisationalUnit

use of com.khartec.waltz.model.orgunit.OrganisationalUnit in project waltz by khartec.

the class AppGenerator method main.

public static void main(String[] args) throws IOException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    ApplicationService applicationDao = ctx.getBean(ApplicationService.class);
    OrganisationalUnitService ouDao = ctx.getBean(OrganisationalUnitService.class);
    List<String> animals = IOUtilities.readLines(AppGenerator.class.getClassLoader().getResourceAsStream("animals.txt"));
    OrganisationalUnit[] organisationalUnits = ouDao.findAll().toArray(new OrganisationalUnit[0]);
    List<AppRegistrationRequest> registrationRequests = new ArrayList<>();
    for (int i = 0; i < 5000; i++) {
        String animal = randomPick(animals.toArray(new String[0])) + " - " + i;
        OrganisationalUnit organisationalUnit = randomPick(organisationalUnits);
        LifecyclePhase phase = rnd.nextInt(10) > 7 ? randomPick(LifecyclePhase.values()) : LifecyclePhase.PRODUCTION;
        Criticality businessCriticality = rnd.nextInt(10) > 7 ? randomPick(Criticality.values()) : Criticality.HIGH;
        AppRegistrationRequest app = ImmutableAppRegistrationRequest.builder().name(animal).assetCode("wltz-0" + i).description("All about " + animal).applicationKind(randomPick(ApplicationKind.values())).lifecyclePhase(phase).overallRating(randomPick(RagRating.R, RagRating.A, RagRating.A, RagRating.G, RagRating.G)).organisationalUnitId(organisationalUnit.id().get()).businessCriticality(businessCriticality).build();
        registrationRequests.add(app);
    }
    dsl.deleteFrom(AUTHORITATIVE_SOURCE).execute();
    dsl.deleteFrom(APPLICATION).execute();
    registrationRequests.forEach(a -> applicationDao.registerApp(a, "admin"));
}
Also used : OrganisationalUnitService(com.khartec.waltz.service.orgunit.OrganisationalUnitService) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ArrayList(java.util.ArrayList) DSLContext(org.jooq.DSLContext) OrganisationalUnit(com.khartec.waltz.model.orgunit.OrganisationalUnit) LifecyclePhase(com.khartec.waltz.model.application.LifecyclePhase) AppRegistrationRequest(com.khartec.waltz.model.application.AppRegistrationRequest) ImmutableAppRegistrationRequest(com.khartec.waltz.model.application.ImmutableAppRegistrationRequest) ApplicationService(com.khartec.waltz.service.application.ApplicationService) Criticality(com.khartec.waltz.model.Criticality)

Example 2 with OrganisationalUnit

use of com.khartec.waltz.model.orgunit.OrganisationalUnit in project waltz by khartec.

the class EntityStatisticGenerator method createPreComputedStatsFor.

private void createPreComputedStatsFor(EntityStatisticDefinition defn, OrganisationalUnit[] orgUnits, EntityStatisticValueDao valueDao) {
    Random rnd = new Random(System.currentTimeMillis());
    List<EntityStatisticValue> values = streamOrgUnitRefs(orgUnits).map(appRef -> {
        String result = randomPick("COMPLIANT", "PARTIALLY_COMPLIANT", "NON_COMPLIANT");
        return ImmutableEntityStatisticValue.builder().entity(appRef).current(true).state(StatisticValueState.PROVIDED).outcome(result).value(String.valueOf(rnd.nextInt(5000))).statisticId(defn.id().get()).createdAt(LocalDateTime.now()).provenance(PROVENANCE).build();
    }).collect(Collectors.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 3 with OrganisationalUnit

use of com.khartec.waltz.model.orgunit.OrganisationalUnit in project waltz by khartec.

the class EntityStatisticGenerator method apply.

@Override
public Map<String, Integer> apply(ApplicationContext context) {
    DSLContext dsl = context.getBean(DSLContext.class);
    ApplicationDao applicationDao = context.getBean(ApplicationDao.class);
    OrganisationalUnitDao organisationalUnitDao = context.getBean(OrganisationalUnitDao.class);
    EntityStatisticValueDao valueDao = context.getBean(EntityStatisticValueDao.class);
    EntityStatisticDefinitionDao definitionDao = context.getBean(EntityStatisticDefinitionDao.class);
    EntityHierarchyService entityHierarchyService = context.getBean(EntityHierarchyService.class);
    Application[] applications = applicationDao.getAll().toArray(new Application[0]);
    OrganisationalUnit[] orgUnits = organisationalUnitDao.findAll().toArray(new OrganisationalUnit[0]);
    dsl.deleteFrom(ENTITY_STATISTIC_DEFINITION).where(ENTITY_STATISTIC_DEFINITION.PROVENANCE.eq("DEMO")).execute();
    System.out.println("deleted existing statistics (provenance: '" + PROVENANCE + "')");
    dsl.update(ENTITY_STATISTIC_VALUE).set(ENTITY_STATISTIC_VALUE.CURRENT, false).where(ENTITY_STATISTIC_VALUE.PROVENANCE.eq("DEMO")).execute();
    System.out.println("marked existing statistic values as non-current (provenance: '" + PROVENANCE + "')");
    definitionDao.insert(SDLC);
    definitionDao.insert(SDLC_TECH);
    definitionDao.insert(SDLC_PROCESS);
    definitionDao.insert(SDLC_JIRA);
    definitionDao.insert(SDLC_SVN);
    definitionDao.insert(SDLC_WIKI);
    definitionDao.insert(AUDIT);
    definitionDao.insert(SERVER_COUNT);
    definitionDao.insert(PRE_COMPUTED);
    createAdoptionStatsFor(SDLC_TECH, applications, valueDao);
    createAdoptionStatsFor(SDLC_PROCESS, applications, valueDao);
    createAdoptionStatsFor(SDLC_JIRA, applications, valueDao);
    createAdoptionStatsFor(SDLC_SVN, applications, valueDao);
    createAdoptionStatsFor(SDLC_WIKI, applications, valueDao);
    createIntStatsFor(AUDIT, applications, valueDao, 20, failIfPositiveFn);
    createIntStatsFor(SDLC, applications, valueDao, 20, failIfPositiveFn);
    createIntStatsFor(SERVER_COUNT, applications, valueDao, 20, (x, y) -> "VIRTUAL");
    createIntStatsFor(SERVER_COUNT, applications, valueDao, 20, (x, y) -> "BARE_METAL");
    createPreComputedStatsFor(PRE_COMPUTED, orgUnits, valueDao);
    entityHierarchyService.buildFor(EntityKind.ENTITY_STATISTIC);
    System.out.println("Rebuilt entity hierarchy");
    return null;
}
Also used : OrganisationalUnitDao(com.khartec.waltz.data.orgunit.OrganisationalUnitDao) EntityStatisticDefinitionDao(com.khartec.waltz.data.entity_statistic.EntityStatisticDefinitionDao) EntityStatisticValueDao(com.khartec.waltz.data.entity_statistic.EntityStatisticValueDao) EntityHierarchyService(com.khartec.waltz.service.entity_hierarchy.EntityHierarchyService) DSLContext(org.jooq.DSLContext) ApplicationDao(com.khartec.waltz.data.application.ApplicationDao) OrganisationalUnit(com.khartec.waltz.model.orgunit.OrganisationalUnit) Application(com.khartec.waltz.model.application.Application)

Example 4 with OrganisationalUnit

use of com.khartec.waltz.model.orgunit.OrganisationalUnit 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 5 with OrganisationalUnit

use of com.khartec.waltz.model.orgunit.OrganisationalUnit 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)

Aggregations

OrganisationalUnit (com.khartec.waltz.model.orgunit.OrganisationalUnit)11 Application (com.khartec.waltz.model.application.Application)8 DSLContext (org.jooq.DSLContext)7 AuthoritativeSource (com.khartec.waltz.model.authoritativesource.AuthoritativeSource)5 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)5 OrganisationalUnitDao (com.khartec.waltz.data.orgunit.OrganisationalUnitDao)4 EntityReference (com.khartec.waltz.model.EntityReference)4 OrganisationalUnitService (com.khartec.waltz.service.orgunit.OrganisationalUnitService)4 List (java.util.List)4 EntityKind (com.khartec.waltz.model.EntityKind)3 DataType (com.khartec.waltz.model.datatype.DataType)3 DIConfiguration (com.khartec.waltz.service.DIConfiguration)3 ApplicationService (com.khartec.waltz.service.application.ApplicationService)3 EntityHierarchyService (com.khartec.waltz.service.entity_hierarchy.EntityHierarchyService)3 Collectors.toList (java.util.stream.Collectors.toList)3 IntStream (java.util.stream.IntStream)3 ListUtilities.randomPick (com.khartec.waltz.common.ListUtilities.randomPick)2 SetUtilities (com.khartec.waltz.common.SetUtilities)2 ApplicationDao (com.khartec.waltz.data.application.ApplicationDao)2 AuthoritativeSourceDao (com.khartec.waltz.data.authoritative_source.AuthoritativeSourceDao)2