@Override
public Optional<Long> newInstrument(long creator, long labId, long model, InstrumentDetails instrumentDetails) {
final User actor = Util.USER_FROM_ID.apply(creator);
if (!validator.canUserCreateInstrument(creator)) {
throw new AccessDenied("User isn't permitted to create experiment - laboratory is not specified");
}
if (!validator.canInstrumentBeCreated(labId, instrumentDetails.name, instrumentDetails.serialNumber)) {
throw new AccessDenied("Couldn't create instrument");
}
//TODO: [stanislav.kurilin] email to lab head should be send
final Lab lab = labRepository.findOne(labId);
final Instrument entity = new Instrument(instrumentDetails.name, actor, Util.INSTRUMENT_MODEL_FROM_ID.apply(model), instrumentDetails.serialNumber, instrumentDetails.hplc, instrumentDetails.peripherals, lab);