#512 Code Review of Organization Creation

Companies:
Sberbank
Themes:
SpringSpring BootCode Review

Complete all subexercises from 1 through 7:

// 1. Add the missing annotations

public class OrganizationController {


    private final OrganizationService organizationService;

    public void create(List<Organization> organizations) {
        organizationService.create(organizations);
    }
}

public interface OrganizationService {

    void create(List<Organization> organizations);
}

public class OrganizationServiceImpl implements OrganizationService {

    @Override
    public void create(List<Organization> organizations) {
        // Validate organization attributes
        validate(organizations);

        // Map organizations to entities
        Set<OrganizationEntity> entities = map(organizations);

        // Save organizations to the database
        save(entities);
    }

    private void validate(List<Organization> organizations) {
         // 2. Check that the organization list is not empty

        // 3. Check that no organization has no accounts

        // 4. Count the total number of accounts across all organizations
        //    and check that the number of accounts is not greater than 10

        // 5. For every account, check that
        //    - the account is not empty
        //    - the account contains only digits
    }

    private Set<OrganizationEntity> map(List<Organizatio> organizations) {

        // 6. Remove duplicate accounts
        //    Organization(accounts=[1, 1]) -> Organization(accounts=[1])

        // 7. Build a set of entities from the organization list
        //    Organization(accounts=[1, 2]) -> [OrganizationEntity(account=1), OrganizationEntity(account=2)]

        return null;
    }

    private void save(Set<OrganizationEntity> entities) {
    }
}

@Getter
@Setter
public class Organization {

    /** Accounts */
    private List<String> accounts;
}

@Getter
@Setter
@Entity
@Table(name = "ORGANIZATION")
@EqualsAndHashCode(of = "account")
public class OrganizationEntity {

    /** Record identifier */
    @Id
    @GeneratedValue
    @Column(name = "ID")
    private UUID id;

    /** Account */
    @Column(name = "ACCOUNT")
    private Integer account;
}

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in