def __generate_org_units( self, org_unit_type_uuid, org_unit_level_uuid, financial_org_unit_uuid, legal_org_unit_uuid, ) -> Tuple[Optional[OrgUnit], Optional[OrgUnit], Optional[OrgUnit]]: cost_center = None if self.Hr_Cost_Center: cost_center = OrgUnit.from_simplified_fields( uuid=generate_uuid("unique_org_unit_seed" + self.Hr_Cost_Center), user_key=self.Hr_Cost_Center, name=self.Hr_Cost_Center, parent_uuid=financial_org_unit_uuid, org_unit_hierarchy_uuid=None, org_unit_type_uuid=org_unit_type_uuid, org_unit_level_uuid=org_unit_level_uuid, ) sender_cost_center = None if self.Sender_Cost_Center: sender_cost_center = OrgUnit.from_simplified_fields( uuid=generate_uuid("unique_org_unit_seed" + self.Sender_Cost_Center), user_key=self.Sender_Cost_Center, name=self.Sender_Cost_Center, parent_uuid=financial_org_unit_uuid, org_unit_hierarchy_uuid=None, org_unit_type_uuid=org_unit_type_uuid, org_unit_level_uuid=org_unit_level_uuid, ) legal_company = None if self.Hr_Legal_Company: legal_company = OrgUnit.from_simplified_fields( uuid=generate_uuid("unique_org_unit_seed" + self.Hr_Legal_Company), user_key=self.Hr_Company_Code, name=self.Hr_Legal_Company, parent_uuid=legal_org_unit_uuid, org_unit_hierarchy_uuid=None, org_unit_type_uuid=org_unit_type_uuid, org_unit_level_uuid=org_unit_level_uuid, ) return cost_center, sender_cost_center, legal_company
def get_uuid(self, key: str) -> str: """ Generate uuid if missing :param key: :return: """ if key in self.__cache: return self.__cache[key] uuid = generate_uuid(self.__seed + key) self.__cache[key] = uuid return uuid
def gen_single_klass(facet_uuid: UUID, organisation_uuid: UUID, title: str, scope: Optional[str] = None) -> Klasse: return Klasse.from_simplified_fields( facet_uuid=facet_uuid, uuid=generate_uuid("klasse" + str(facet_uuid) + title), user_key=title, title=title, scope=scope, organisation_uuid=organisation_uuid, )
def ou(user_key): """ convenience :param user_key: :return: """ return [ OrgUnit.from_simplified_fields( uuid=generate_uuid("ou_any_seed_yo" + user_key), user_key=user_key, name="MISSING INFO", org_unit_type_uuid=outu, org_unit_level_uuid=oulu, ) ]
def __generate_engagement_association( org_unit_uuids: Iterable[UUID], engagement_uuid: UUID, association_type_uuid: UUID, from_date: str, to_date: Optional[str], ) -> List[EngagementAssociation]: return [ EngagementAssociation.from_simplified_fields( uuid=generate_uuid("engagement_association" + str(engagement_uuid) + str(org_unit_uuid) + str(association_type_uuid)), org_unit_uuid=org_unit_uuid, engagement_uuid=engagement_uuid, engagement_association_type_uuid=association_type_uuid, from_date=from_date, to_date=to_date, ) for org_unit_uuid in org_unit_uuids ]
def manager_gen(partial_manager: PartialManager) -> Optional[Manager]: try: eng = eng_mapping[partial_manager.engagement_user_key] except KeyError: return None return Manager.from_simplified_fields( uuid=generate_uuid( "manager" + partial_manager.engagement_user_key + str(partial_manager.org_unit_uuid) ), org_unit_uuid=partial_manager.org_unit_uuid, person_uuid=eng.person.uuid, responsibility_uuid=responsibility_uuid, manager_level_uuid=manager_level_uuid, manager_type_uuid=manager_type_uuid, from_date=eng.validity.from_date, to_date=eng.validity.to_date, )
def to_address(value: str, value2: Optional[str], address_type_klasse: Klasse) -> Optional[Address]: if not value: return if address_type_klasse.attributes.properties[0].scope == "PHONE": try: int(value) except Exception: return None return Address.from_simplified_fields( uuid=generate_uuid( str(engagement_uuid) + str(address_type_klasse.uuid) + value + str(value2)), value=value, value2=value2, address_type_uuid=address_type_klasse.uuid, engagement_uuid=engagement_uuid, from_date=from_date, to_date=to_date, visibility_uuid=visibility_uuid, org_uuid=org_uuid, )
def __generate_engagement( self, *, person_uuid: UUID, job_function_uuid_generator: UUIDGenerator, engagement_type_uuid_generator: UUIDGenerator, org_unit_uuids: Dict[str, str], primary_uuid: UUID, ) -> Engagement: engagement_type = (self.Hr_Employee_Type if self.Hr_Employee_Type else self.Hr_Consultant_Type) job_function_uuid = job_function_uuid_generator.get_uuid(self.Title) engagement_type_uuid = engagement_type_uuid_generator.get_uuid( engagement_type) engagement_seed = "unique_engagement_salt_" + self.Initials engagement_uuid = generate_uuid(engagement_seed) from_date, to_date = self.__get_from_to_dates() return Engagement.from_simplified_fields( uuid=engagement_uuid, org_unit_uuid=org_unit_uuids[str(self.Hr_Department_No)], person_uuid=person_uuid, job_function_uuid=job_function_uuid, engagement_type_uuid=engagement_type_uuid, from_date=from_date, to_date=to_date, primary_uuid=primary_uuid, user_key=self.Initials, extension_1=self.Hr_Employee_No, extension_2=self.Hr_Hirakey_Relevant, extension_3=self.Hr_Active_Status, extension_4=self.Ee_Subgroup, extension_5=self.Career_Level, extension_6=self.Position_Level, extension_7=self.Career_Track, )
def read_values(base_path: Path) -> Iterable[Iterable[MoObj]]: base = ValidMo.from_scratch() gen_org_klass = partial( gen_single_klass, organisation_uuid=base.organisation.uuid ) base_objs = [x[1] for x in base] address_classes = AddressKlasses.from_simplified_fields( organisation_uuid=base.organisation.uuid, engagement_address_type_uuid=base.employee_address_type.uuid, employee_address_type_uuid=base.employee_address_type.uuid, ) address_classes_iterable = [x[1] for x in address_classes] ou_type_unit = gen_org_klass( facet_uuid=base.org_unit_type.uuid, title="Unit", ) ou_level_l1 = gen_org_klass( facet_uuid=base.org_unit_level.uuid, title="L1", ) man_type_man = gen_org_klass( facet_uuid=base.manager_type.uuid, title="Manager", ) man_level_m1 = gen_org_klass( facet_uuid=base.manager_level.uuid, title="M1", ) resp_r1 = gen_org_klass( facet_uuid=base.responsibility.uuid, title="R1", ) not_primary = gen_org_klass( facet_uuid=base.primary_type.uuid, title="Non-primary", ) visible = gen_org_klass( facet_uuid=base.visibility.uuid, title="Visible", ) not_visible = gen_org_klass( facet_uuid=base.visibility.uuid, title="Not visible", ) ea_assoc = gen_org_klass( facet_uuid=base.engagement_association_type.uuid, title="Association", ) classes = [ ou_type_unit, ou_level_l1, man_type_man, man_level_m1, resp_r1, not_primary, visible, not_visible, ea_assoc, ] classes.extend(address_classes_iterable) org_units, partial_managers = read_csv( path=base_path / "gir_orsted_hierarki_linje.csv", org_unit_type_uuid=ou_type_unit.uuid, org_unit_level_uuid=ou_level_l1.uuid, ) org_units.extend(missing_ous(ou_type_unit.uuid, ou_level_l1.uuid)) # department_no: uuid ou_mapping = {ou.user_key: ou.uuid for ou in flatten(org_units)} ou_fin = OrgUnit.from_simplified_fields( uuid=generate_uuid("w/e" + "fin"), user_key="financial_placeholder", name="Financial Organisation", org_unit_type_uuid=ou_type_unit.uuid, org_unit_level_uuid=ou_level_l1.uuid, ) ou_legal = OrgUnit.from_simplified_fields( uuid=generate_uuid("w/e" + "legal"), user_key="legal_placeholder", name="Legal Organisation", org_unit_type_uuid=ou_type_unit.uuid, org_unit_level_uuid=ou_level_l1.uuid, ) engagement_type_uuid_generator = UUIDGenerator("engagement_type") job_function_uuid_generator = UUIDGenerator("job_function") ( employees, additional_engagement_ous, engagements, engagement_associations, addresses, ) = read_emd( path=base_path / "gir_from_emd.csv", org_unit_uuids=ou_mapping, primary_uuid=not_primary.uuid, engagement_type_uuid_generator=engagement_type_uuid_generator, job_function_uuid_generator=job_function_uuid_generator, visible_uuid=visible.uuid, not_visible_uuid=not_visible.uuid, address_klasses=address_classes, org_unit_type_uuid=ou_type_unit.uuid, financial_org_unit_uuid=ou_fin.uuid, legal_org_unit_uuid=ou_legal.uuid, engagement_association_type_uuid=ea_assoc.uuid, org_unit_level_uuid=ou_level_l1.uuid, org_uuid=base.organisation.uuid, ) fixture2 = ( *employees, *additional_engagement_ous, *engagements, ) eng_mapping = {x.user_key: x for x in flatten(engagements)} managers = gen_managers( partial_managers=partial_managers, eng_mapping=eng_mapping, responsibility_uuid=resp_r1.uuid, manager_level_uuid=man_level_m1.uuid, manager_type_uuid=man_type_man.uuid, ) # more shitty code: managers = list(map(lambda x: [x], managers)) classes.extend( klasses_from_uuid_gen( facet_uuid=base.engagement_type.uuid, organisation_uuid=base.organisation.uuid, uuid_gen=engagement_type_uuid_generator, ) ) classes.extend( klasses_from_uuid_gen( facet_uuid=base.engagement_job_function.uuid, organisation_uuid=base.organisation.uuid, uuid_gen=job_function_uuid_generator, ) ) fixture = base_objs, classes, *org_units, [ou_fin], [ou_legal] # return (*fixture,) # return (*fixture2,) # return *engagement_associations, *managers, *addresses # return *managers[10:20], *addresses[10:20] # return (*managers,) # return (*addresses[9:],) return *fixture, *fixture2, *engagement_associations, *managers, *addresses
def from_scratch(cls) -> "ValidMo": """ For when you know nothing, and don't actually care :return: A fully equipped MO; With autogenerated but consistent uuids """ seed = "the_best_seed" org_uuid = generate_uuid(seed) organisation = Organisation.from_simplified_fields(uuid=org_uuid, name="Org_name", user_key="Org_bvn") org_unit_address_type = Facet.from_simplified_fields( uuid=generate_uuid(seed + "org_unit_address_type"), user_key="org_unit_address_type", organisation_uuid=org_uuid, ) employee_address_type = Facet.from_simplified_fields( uuid=generate_uuid(seed + "employee_address_type"), user_key="employee_address_type", organisation_uuid=org_uuid, ) address_property = Facet.from_simplified_fields( uuid=generate_uuid(seed + "address_property"), user_key="address_property", organisation_uuid=org_uuid, ) engagement_job_function = Facet.from_simplified_fields( uuid=generate_uuid(seed + "engagement_job_function"), user_key="engagement_job_function", organisation_uuid=org_uuid, ) org_unit_type = Facet.from_simplified_fields( uuid=generate_uuid(seed + "org_unit_type"), user_key="org_unit_type", organisation_uuid=org_uuid, ) engagement_type = Facet.from_simplified_fields( uuid=generate_uuid(seed + "engagement_type"), user_key="engagement_type", organisation_uuid=org_uuid, ) engagement_association_type = Facet.from_simplified_fields( uuid=generate_uuid(seed + "engagement_association_type"), user_key="engagement_association_type", organisation_uuid=org_uuid, ) association_type = Facet.from_simplified_fields( uuid=generate_uuid(seed + "association_type"), user_key="association_type", organisation_uuid=org_uuid, ) role_type = Facet.from_simplified_fields( uuid=generate_uuid(seed + "role_type"), user_key="role_type", organisation_uuid=org_uuid, ) leave_type = Facet.from_simplified_fields( uuid=generate_uuid(seed + "leave_type"), user_key="leave_type", organisation_uuid=org_uuid, ) manager_type = Facet.from_simplified_fields( uuid=generate_uuid(seed + "manager_type"), user_key="manager_type", organisation_uuid=org_uuid, ) responsibility = Facet.from_simplified_fields( uuid=generate_uuid(seed + "responsibility"), user_key="responsibility", organisation_uuid=org_uuid, ) manager_level = Facet.from_simplified_fields( uuid=generate_uuid(seed + "manager_level"), user_key="manager_level", organisation_uuid=org_uuid, ) visibility = Facet.from_simplified_fields( uuid=generate_uuid(seed + "visibility"), user_key="visibility", organisation_uuid=org_uuid, ) time_planning = Facet.from_simplified_fields( uuid=generate_uuid(seed + "time_planning"), user_key="time_planning", organisation_uuid=org_uuid, ) org_unit_level = Facet.from_simplified_fields( uuid=generate_uuid(seed + "org_unit_level"), user_key="org_unit_level", organisation_uuid=org_uuid, ) primary_type = Facet.from_simplified_fields( uuid=generate_uuid(seed + "primary_type"), user_key="primary_type", organisation_uuid=org_uuid, ) org_unit_hierarchy = Facet.from_simplified_fields( uuid=generate_uuid(seed + "org_unit_hierarchy"), user_key="org_unit_hierarchy", organisation_uuid=org_uuid, ) return ValidMo( organisation=organisation, org_unit_address_type=org_unit_address_type, employee_address_type=employee_address_type, address_property=address_property, engagement_job_function=engagement_job_function, org_unit_type=org_unit_type, engagement_type=engagement_type, engagement_association_type=engagement_association_type, association_type=association_type, role_type=role_type, leave_type=leave_type, manager_type=manager_type, responsibility=responsibility, manager_level=manager_level, visibility=visibility, time_planning=time_planning, org_unit_level=org_unit_level, primary_type=primary_type, org_unit_hierarchy=org_unit_hierarchy, )
def __get_parent_uuid(self) -> Optional[UUID]: if not self.__path[1:]: return None return generate_uuid(str(self.__path[:-1]))
def __get_uuid(self) -> UUID: return generate_uuid(str(self.__path))
def __generate_addresses( self, visible_uuid, not_visible_uuid, engagement_uuid, address_klasses: AddressKlasses, from_date, to_date, person_uuid, org_uuid: UUID, ) -> List[Address]: visibility_uuid = (visible_uuid if self.Phonebook_Relevant else not_visible_uuid) address_candidates = [ (self.Email, None, address_klasses.EMAIL), (self.Phone, None, address_klasses.PHONE), (self.Mobile, None, address_klasses.MOBILE), (self.Hr_Country_Code, None, address_klasses.HR_COUNTRY_CODE), (self.Hr_Tdb_Fixed_Phone, None, address_klasses.HR_TDB_FIXED_PHONE), (self.Hr_Tdb_Mobile_Phone, None, address_klasses.HR_TDB_MOBILE_PHONE), (self.Consultant_Email, None, address_klasses.CONSULTANT_EMAIL), ( self.Hr_Location_Id, self.Office, address_klasses.HR_LOCATION_ID_and_OFFICE, ), ] def to_address(value: str, value2: Optional[str], address_type_klasse: Klasse) -> Optional[Address]: if not value: return if address_type_klasse.attributes.properties[0].scope == "PHONE": try: int(value) except Exception: return None return Address.from_simplified_fields( uuid=generate_uuid( str(engagement_uuid) + str(address_type_klasse.uuid) + value + str(value2)), value=value, value2=value2, address_type_uuid=address_type_klasse.uuid, engagement_uuid=engagement_uuid, from_date=from_date, to_date=to_date, visibility_uuid=visibility_uuid, org_uuid=org_uuid, ) addresses = list( filter( lambda tmp: tmp is not None, [ to_address(value, value2, address_type_klasse) for value, value2, address_type_klasse in address_candidates ], )) if self.Country_Of_Residence: addresses.append( Address.from_simplified_fields( uuid=generate_uuid( str(person_uuid) + str(address_klasses.COUNTRY_OF_RESIDENCE.uuid) + self.Country_Of_Residence), value=self.Country_Of_Residence, value2=None, address_type_uuid=address_klasses.COUNTRY_OF_RESIDENCE. uuid, person_uuid=person_uuid, from_date=from_date, to_date=to_date, visibility_uuid=visibility_uuid, org_uuid=org_uuid, )) return addresses
def __generate_employee(self) -> Employee: name = f"{self.First_Name} {self.Last_Name}" person_uuid = generate_uuid(name) return Employee(uuid=person_uuid, name=name, seniority=self.Seniority)